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 |
||
17 | class Row extends Nette\Object |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * @var DataGrid |
||
22 | */ |
||
23 | protected $datagrid; |
||
24 | |||
25 | /** |
||
26 | * @var mixed |
||
27 | */ |
||
28 | protected $item; |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $primary_key; |
||
34 | |||
35 | /** |
||
36 | * @var mixed |
||
37 | */ |
||
38 | protected $id; |
||
39 | |||
40 | /** |
||
41 | * @var Html |
||
42 | */ |
||
43 | protected $control; |
||
44 | |||
45 | |||
46 | /** |
||
47 | * @param mixed $item |
||
48 | * @param string $primary_key |
||
49 | */ |
||
50 | public function __construct(DataGrid $datagrid, $item, $primary_key) |
||
58 | |||
59 | |||
60 | /** |
||
61 | * @return Html |
||
62 | */ |
||
63 | public function getControl() |
||
67 | |||
68 | |||
69 | /** |
||
70 | * Get id value of item |
||
71 | * @return mixed |
||
72 | */ |
||
73 | public function getId() |
||
77 | |||
78 | |||
79 | /** |
||
80 | * Get item value of key |
||
81 | * @param mixed $key |
||
82 | * @return mixed |
||
83 | */ |
||
84 | public function getValue($key) |
||
106 | |||
107 | |||
108 | /** |
||
109 | * @return string |
||
110 | */ |
||
111 | public function getClass() |
||
119 | |||
120 | |||
121 | /** |
||
122 | * LeanMapper: Access object properties to get a item value |
||
123 | * @param LeanMapper\Entity $item |
||
124 | * @param mixed $key |
||
125 | * @return mixed |
||
126 | */ |
||
127 | public function getLeanMapperEntityProperty(LeanMapper\Entity $item, $key) |
||
149 | |||
150 | |||
151 | /** |
||
152 | * Doctrine: Access object properties to get a item value |
||
153 | * @param mixed $item |
||
154 | * @param mixed $key |
||
155 | * @return mixed |
||
156 | */ |
||
157 | public function getDoctrineEntityProperty($item, $key) |
||
180 | |||
181 | |||
182 | /** |
||
183 | * Get original item |
||
184 | * @return mixed |
||
185 | */ |
||
186 | public function getItem() |
||
190 | |||
191 | |||
192 | /** |
||
193 | * Has particular row group actions allowed? |
||
194 | * @return bool |
||
195 | */ |
||
196 | public function hasGroupAction() |
||
202 | |||
203 | |||
204 | /** |
||
205 | * Has particular row and action allowed? |
||
206 | * @param mixed $key |
||
207 | * @return bool |
||
208 | */ |
||
209 | public function hasAction($key) |
||
215 | |||
216 | } |
||
217 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.