Question

I'm using doxygen with my php code. Some of my classes are wrapped in if statements in a way similar to this:

if(!class_exists('FooBar', false)) {

    /**
     * Docs
     **/
    class FooBar
    {

    }
}

doxygen doesn't seem to understand this and ignores class FooBar completely. Is there a workaround?

Patching doxygen would be no problem, feel free to suggest how (I guess somewhere in scanner.l)

Was it helpful?

Solution 2

As I don't speak PHP I'll offer a possible Doxygen-related answer:

Try surrounding the wrapper components with \cond commands that hide code from doxygen.

/** \cond */
if(!class_exists('FooBar', false)) {
/** \endcond */

    /**
     * Docs
     **/
    class FooBar
    {

    }

/** \cond */
}
/** \endcond */

I am unsure if this will work - it rather depends on the parsing order of Doxygen - but seems worth a try before you start opening the complications that modifying doxygen will introduce.

OTHER TIPS

Doxygen does not interpret your code with its static analysis, therefore the if-clause is just code and the class definition not taken care of for documentation (which also does make sense, as it's only conditional and most likely not needed).

Externalize the class definition so that static code analysis has no problem with it. This class defintion then can be also easily required. It's also compatible with autoloading (not documented in this answer), Doxygen has no problem with it.

...

if (!class_exists('Myfile', false))
{
    require(__DIR__ . '/Myfile.php');
}

...

Myfile.php

<?php
class Myfile
{
    ...
}

You can also use this filter (copied from GitHub):

<?php

// Get the input
$source = file_get_contents($argv[1]);
// removes the whole line
list($head,$tail) = preg_split('/.*if\(!class_exists\(.+/', $source, 2);
$openingBracePos = strpos($tail,'{');
$closingBracePos = strrpos($tail,'}');
if($openingBracePos !== false && $closingBracePos !== false)
    $source = $head . substr($tail,$openingBracePos+1,
                             $closingBracePos-$openingBracePos-1);
// Output
echo $source;

This filter removes the if(!class_exists(...)) statement, so doxygen understands the code, without changes in the code itself.

remove the false. it's going to work

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top