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 |
||
14 | abstract class AbstractAnalyticsCommandHelper |
||
15 | { |
||
16 | /** @var ConfigHelper $configHelper */ |
||
17 | protected $configHelper; |
||
18 | |||
19 | /** @var QueryHelper $queryHelper */ |
||
20 | protected $query; |
||
21 | |||
22 | /** @var EntityManager $em */ |
||
23 | protected $em; |
||
24 | |||
25 | /** @var OutputInterface $output */ |
||
26 | protected $output; |
||
27 | |||
28 | /** |
||
29 | * Constructor |
||
30 | * |
||
31 | * @param $configHelper |
||
32 | * @param $queryHelper |
||
33 | * @param $output |
||
34 | * @param $em |
||
35 | */ |
||
36 | public function __construct($configHelper, $queryHelper, $output, $em) |
||
43 | |||
44 | /** |
||
45 | * @param AnalyticsOverview $overview |
||
46 | * |
||
47 | * @return array |
||
|
|||
48 | * |
||
49 | * @throws \Exception |
||
50 | */ |
||
51 | protected function getTimestamps(AnalyticsOverview $overview) |
||
70 | |||
71 | /** |
||
72 | * Get the extra data for an overview, can be overridden |
||
73 | * |
||
74 | * @param AnalyticsOverview $overview |
||
75 | * |
||
76 | * @return array |
||
77 | */ |
||
78 | protected function getExtra(AnalyticsOverview $overview) |
||
89 | |||
90 | /** |
||
91 | * Executes the query |
||
92 | * |
||
93 | * @param AnalyticsOverview $overview |
||
94 | * @param $metrics |
||
95 | * |
||
96 | * @return mixed |
||
97 | * @throws \Exception |
||
98 | */ |
||
99 | View Code Duplication | protected function executeQuery(AnalyticsOverview $overview, $metrics) |
|
113 | |||
114 | public abstract function getData(AnalyticsOverview $overview); |
||
115 | |||
116 | } |
||
117 |
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.