2

How can I make getter/setter methods to automatically use DocBlock description from their respective fields? Or maybe there are any other ways to solve this: see DocBlocks on getters/setters without manually copy-pasting every single one.

Consider this example:
enter image description here

There is some comment on field $name (1), however, it will almost never be seen as the field is private and intended to be used with getter/setter methods. However, on those methods IDE does not show any comments from field variables (2).

You can, of course, simply copy-paste same description to both methods. But it becomes very difficult to manage when object has a dozen or more properties, all with getters/setters and extensively commented. It requires a lot of manual work to fix the same text in 3 places on every change and is very error-prone.

IDE is PhpStorm.
I'd prefer to do it without magic __get __set methods.

mindaugasw
  • 1,116
  • 13
  • 18
  • AFAIK -- you cannot. `@inheritDoc` tag works with parents only (e.g. to copy (inherit) description from the same method in the parent class). – LazyOne Feb 21 '21 at 15:49
  • I'm aware of that :( was thinking maybe there are at least some dirty workarounds, or IDE-specific hacks. – mindaugasw Feb 21 '21 at 17:15
  • 1
    I'm not aware about IDE-specific hanks here. I may suggest submitting a Feature Request ticket to the [PhpStorm Issue Tracker](https://youtrack.jetbrains.com/issues/WI) . Your request/desired functionality certainly makes sense to me. E.g. "using some tag (e.g. `@see` or whatnot) show such description from that field when invoking documentation on such method"... – LazyOne Feb 21 '21 at 17:50

1 Answers1

2

The only option I know is using @see or @link. We can use them inline as well. This is how it looks in Phpstorm:

https://i.stack.imgur.com/bfSg4.png

The link in the description is clickable. Without a mouse, we can use a tab key to move a cursor on the link (3 x tab and enter).

First popup

Final view:

Final popup