Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 13 | class CGIRequest extends Generic |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var bool |
||
| 17 | */ |
||
| 18 | public $terminateOnAbort = false; |
||
| 19 | /** |
||
| 20 | * @var \PHPDaemon\Core\ShellCommand |
||
| 21 | */ |
||
| 22 | public $proc; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Constructor. |
||
| 26 | * @return void |
||
| 27 | */ |
||
| 28 | public function init() |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Called when request iterated. |
||
| 74 | * @return void |
||
| 75 | */ |
||
| 76 | public function run() |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Called when the request aborted. |
||
| 90 | * @return void |
||
| 91 | */ |
||
| 92 | public function onAbort() |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Called when new data received from process. |
||
| 101 | * @param object $process Process pointer. |
||
| 102 | * @param string $data Data. |
||
| 103 | * @return void |
||
| 104 | */ |
||
| 105 | public function onReadData($process, $data) |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Called when new piece of request's body is received. |
||
| 112 | * @param string $c Piece of request's body. |
||
| 113 | * @return void |
||
| 114 | */ |
||
| 115 | public function stdin($c) |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Called when the request aborted. |
||
| 126 | * @param \PHPDaemon\Core\ShellCommand $process |
||
| 127 | * @return void |
||
| 128 | */ |
||
| 129 | public function onWrite($process) |
||
| 135 | } |
||
| 136 |
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.