Documenting your code in PHP

Whilst working on this model, I found myself forgetting various parameters or names of methods I had created. I can’t believe how much I rely on an IDE to provide me with all my prompts.

I did try setting up Eclipse again with PDT (had tried to use phpEclipse in the past with dissapointing results) yet I was getting UI errors all over, no matter what I tried (updating the JRE, grabbing various packages) I could not get the thing to work.

So I resorted to the next best thing, I went and found something called phpDoc. It reads DocBlocks from your code and creates a set of html pages containing all the information about your code.

Again, I installed it from pear on the command line, there are lots of site out there to help with installing it on Windows. Once installed, you can use the phpdoc -h to get all the command line parameters.

Similar to my last post, I use an msbuild script to run the documentation tasks


<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">

    <PropertyGroup>
        <BuildDir>$(MSBuildProjectDirectory)</BuildDir>
        <DocumentationTitle>Dynamic Data Model</DocumentationTitle>
        <HelpOutput>HTML:Smarty:HandS</HelpOutput>
        <DocumentationFolder>$(BuildDir)Documentation</DocumentationFolder>
    </PropertyGroup>

    <ItemGroup>
        <CodeFiles Include="$(BuildDir)***.php" Exclude="$(BuildDir)**.svn***.*;
                                 $(BuildDir)**tests***.*" />
    </ItemGroup>

    <Target Name="Clean">
        <RemoveDir Directories="$(DocumentationFolder)" Condition="Exists('$(DocumentationFolder)')" />
    </Target>

    <Target Name="Setup" DependsOnTargets="Clean">
        <MakeDir Directories="$(DocumentationFolder)" Condition="!Exists('$(DocumentationFolder)')" />
    </Target>

    <Target Name="Build" DependsOnTargets="Setup">
        <CallTarget Targets="BuildDocumentation" />
    </Target>

    <Target Name="BuildDocumentation" DependsOnTargets="Setup">
        <CreateProperty Value="@(CodeFiles, ',')">
            <Output TaskParameter="Value" PropertyName="FilesToDocument" />
        </CreateProperty>

        <Exec Command='phpdoc --sourcecode --target "$(DocumentationFolder)" --output $(HelpOutput) --title "$(DocumentationTitle)" --filename $(FilesToDocument)' />
    </Target>
</Project>

Leave a Reply