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 |
||
23 | View Code Duplication | class RemoveSubscriber implements EventSubscriberInterface |
|
|
|||
24 | { |
||
25 | /** |
||
26 | * @var DocumentRegistry |
||
27 | */ |
||
28 | private $documentRegistry; |
||
29 | |||
30 | /** |
||
31 | * @var NodeManager |
||
32 | */ |
||
33 | private $nodeManager; |
||
34 | |||
35 | public function __construct( |
||
42 | |||
43 | /** |
||
44 | * {@inheritdoc} |
||
45 | */ |
||
46 | public static function getSubscribedEvents() |
||
52 | |||
53 | /** |
||
54 | * Remove the given documents node from PHPCR session and optionally |
||
55 | * remove any references to the node. |
||
56 | * |
||
57 | * @param RemoveEvent $event |
||
58 | */ |
||
59 | public function handleRemove(RemoveEvent $event) |
||
66 | } |
||
67 |
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.