phpdocpreconditions

PHPDoc preconditions


How to tag preconditions with PHPDoc? I have an object, and before calling a function another function must have been called:

$myObject = new MyClass();
$myObject->mustDoThis();
$myObject->beforeThis();

So the documentation for beforeThis() would look like:

/**
 * @precondition mustDoThis() must be called before this function is
 */

Or is there another way around this? Perhaps a @throw clause would be enough.


Solution

  • As far as I know, there's no standard @precondition or @postcondition tags for PhpDoc but I use them anyway as it is a nice way to hint the developer implementing the class/interface/trait.