Frage

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.

War es hilfreich?

Lösung

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.

Andere Tipps

According to the book "Clean Code" written by Robert C. Martin, the scenario you have described is a temporally coupled pair and you should solve it by making a new method which calls those methods in the right order.

The client shouldn't know in which order should call methods so encapsulate the logic.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top