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) |
||
118 | |||
119 | |||
120 | /** |
||
121 | * @return Action[] |
||
122 | */ |
||
123 | public function getActions() |
||
127 | |||
128 | |||
129 | /** |
||
130 | * @param string $key |
||
131 | * @return Action |
||
132 | */ |
||
133 | View Code Duplication | public function getAction($key) |
|
143 | |||
144 | |||
145 | /** |
||
146 | * Column can have variables that will be passed to custom template scope |
||
147 | * @return array |
||
148 | */ |
||
149 | public function getTemplateVariables() |
||
155 | |||
156 | } |
||
157 |
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@property
annotation 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.