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 |
||
5 | class AdminPanel |
||
6 | { |
||
7 | /** |
||
8 | * @var AdminPanelAdaptorInterface[] |
||
9 | */ |
||
10 | private $adaptors = array(); |
||
11 | |||
12 | /** |
||
13 | * @var AdminPanelAdaptorInterface[] |
||
14 | */ |
||
15 | private $sorted = array(); |
||
16 | |||
17 | /** |
||
18 | * @var AdminPanelActionInterface[] |
||
19 | */ |
||
20 | private $actions = null; |
||
21 | |||
22 | /** |
||
23 | * Add admin panel adaptor |
||
24 | * |
||
25 | * @param AdminPanelAdaptorInterface $adaptor |
||
26 | */ |
||
27 | public function addAdminPanelAdaptor(AdminPanelAdaptorInterface $adaptor, $priority = 0) |
||
32 | |||
33 | /** |
||
34 | * Return current admin panel actions |
||
35 | */ |
||
36 | public function getAdminPanelActions() |
||
48 | |||
49 | /** |
||
50 | * Get adaptors sorted by priority. |
||
51 | * |
||
52 | * @return \Kunstmaan\AdminBundle\Helper\AdminPanel\AdminPanelAdaptorInterface[] |
||
53 | */ |
||
54 | private function getAdaptors() |
||
62 | |||
63 | /** |
||
64 | * Sorts the internal list of adaptors by priority. |
||
65 | */ |
||
66 | View Code Duplication | private function sortAdaptors() |
|
75 | } |
||
76 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.