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 |
||
13 | final class CountController |
||
14 | { |
||
15 | const ACTION = 'countAction'; |
||
16 | |||
17 | /** @var string */ |
||
18 | private $fqcn; |
||
19 | /** @var CriteriaConfiguratorInterface */ |
||
20 | private $configurator; |
||
21 | /** @var Selectable */ |
||
22 | private $repository; |
||
23 | /** @var EventDispatcherInterface */ |
||
24 | private $evm; |
||
25 | |||
26 | /** |
||
27 | * CountController constructor. |
||
28 | * |
||
29 | * @param string $fqcn |
||
30 | * @param Selectable $repository |
||
31 | * @param CriteriaConfiguratorInterface $configurator |
||
32 | * @param EventDispatcherInterface $evm |
||
33 | */ |
||
34 | 5 | View Code Duplication | public function __construct( |
45 | |||
46 | /** |
||
47 | * Performs counting search of entities and returns count |
||
48 | * |
||
49 | * @param array $criteria |
||
50 | * |
||
51 | * @return integer |
||
52 | * @throws CriteriaConfigurationException |
||
53 | */ |
||
54 | 5 | public function countAction(array $criteria) |
|
65 | } |
||
66 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.