Is there a correct or standard way to do this?
For example:
AbstractFoo.php:
abstract class AbstractFoo {
/**
* Does the phpdoc go here?
*/
public function fooFunction();
}
Foo.php:
class Foo extends AbstractFoo {
/**
* Or does the phpdoc go here?
*/
public function fooFunction(){
// some implementation
}
}
Consider the following issues:
If you put the phpdoc in the abstract FooFunction(), and control + click $foo->FooFunction()
, you will end up at the Foo
class' FooFunction()
, which is undocumented, and not immediately obvious that it's implementing an abstract function. And if it was obvious, there's no easy way to get to the phpdoc in the abstract function, without
If you put the phpdoc only in the children functions, then you're faced with duplicating phpdocs across the children functions of n number of inheriting classes.
If you put the phpdoc in both, the abstract function's phpdoc becomes purposeless, unless a child class did not have a phpdoc, wanting to inherit the abstract's phpdoc. But even in this case, again, there's no easy way to navigate to that abstract phpdoc.
You should document an interface or abstract implementation. Otherwise, use @inheritdoc/document your implementation of an interface method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With