-
-
Notifications
You must be signed in to change notification settings - Fork 640
Closed
Labels
Description
A pattern I use quite a lot in PHP is this:
abstract class ContainerBase {
private $buffer = array();
function __get($key) {
return array_key_exists($key, $this->buffer)
? $this->buffer[$key]
: $this->buffer[$key] = $this->{'calc_' . $key}();
}
}
/**
* @property \X $xyz
*/
interface MyContainerInterface {}
class MyContainer extends ContainerBase implements MyContainerInterface {
/**
* @return \X
*
* @see \MyContainerInterface::$xyz
*/
protected function calc_xyz() {..}
}I made it a habit to always add the @see tags to associate a method with a property. This is kind of ok, but requires too much work to set up, and the IDE has no way to validate it.
I wonder how this could be documented, to allow the IDE to
- Complain if a 'calc_*()' method for a specific property is missing, and propose to auto-create it.
- Complain if the @Property for a given 'calc_*()' method is missing, and propose to auto-create it.
- Complain if the return type of 'calc_*()' does not match the property type.
- Allow to easily navigate between the @Property and the method.
- Of course, it should be possible to use a different prefix than 'calc_'. E.g. 'get_' or 'create_'.
(Proposals in comments)
Reactions are currently unavailable