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 |
||
| 16 | class MultiAction extends Column |
||
| 17 | { |
||
| 18 | |||
| 19 | use Traits\TButtonTryAddIcon; |
||
| 20 | use Traits\TButtonIcon; |
||
| 21 | use Traits\TButtonClass; |
||
| 22 | use Traits\TButtonTitle; |
||
| 23 | use Traits\TButtonText; |
||
| 24 | use Traits\TButtonCaret; |
||
| 25 | use Traits\TLink; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var DataGrid |
||
| 29 | */ |
||
| 30 | protected $grid; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var string |
||
| 34 | */ |
||
| 35 | protected $name; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var array |
||
| 39 | */ |
||
| 40 | protected $actions = []; |
||
| 41 | |||
| 42 | |||
| 43 | /** |
||
| 44 | * @param DataGrid $grid |
||
| 45 | */ |
||
| 46 | public function __construct(DataGrid $grid, $name) |
||
| 53 | |||
| 54 | |||
| 55 | /** |
||
| 56 | * @return Html |
||
| 57 | */ |
||
| 58 | public function renderButton() |
||
| 87 | |||
| 88 | |||
| 89 | /** |
||
| 90 | * @param string $key |
||
| 91 | * @param string $name |
||
| 92 | * @param string $href |
||
| 93 | * @param array|null $params |
||
| 94 | * @return static |
||
| 95 | */ |
||
| 96 | public function addAction($key, $name, $href = NULL, array $params = NULL) |
||
| 116 | |||
| 117 | |||
| 118 | /** |
||
| 119 | * @return Action[] |
||
| 120 | */ |
||
| 121 | public function getActions() |
||
| 125 | |||
| 126 | |||
| 127 | /** |
||
| 128 | * @param string $key |
||
| 129 | * @return Action |
||
| 130 | */ |
||
| 131 | View Code Duplication | public function getAction($key) |
|
| 141 | |||
| 142 | |||
| 143 | /** |
||
| 144 | * Column can have variables that will be passed to custom template scope |
||
| 145 | * @return array |
||
| 146 | */ |
||
| 147 | public function getTemplateVariables() |
||
| 153 | |||
| 154 | } |
||
| 155 |
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read 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.