Reputation: 4020
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.
Upvotes: 2
Views: 460
Reputation: 1
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.
Upvotes: 0
Reputation: 1036
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.
Upvotes: 2