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 | final class UpdateController |
||
15 | { |
||
16 | const ACTION = 'patchAction'; |
||
17 | |||
18 | /** @var ObjectManager */ |
||
19 | private $manager; |
||
20 | /** @var EventDispatcherInterface */ |
||
21 | private $evm; |
||
22 | /** @var ObjectRepository */ |
||
23 | private $repository; |
||
24 | /** @var EntityProcessorInterface */ |
||
25 | private $processor; |
||
26 | |||
27 | /** |
||
28 | * UpdateController constructor. |
||
29 | * |
||
30 | * @param ObjectRepository $repository |
||
31 | * @param EntityProcessorInterface $processor |
||
32 | * @param ObjectManager $manager |
||
33 | * @param EventDispatcherInterface $evm |
||
34 | */ |
||
35 | 10 | View Code Duplication | public function __construct( |
46 | |||
47 | /** |
||
48 | * @param mixed $identifier |
||
49 | * @param mixed $data |
||
50 | * |
||
51 | * @return object |
||
52 | * @throws EntityNotFoundException |
||
53 | */ |
||
54 | 10 | public function patchAction($identifier, $data) |
|
69 | } |
||
70 |
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.