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 | View Code Duplication | class MetadataAttributeNotFoundException extends DocumentException |
|
|
|||
14 | { |
||
15 | /** |
||
16 | * Name of not found attribute of metadata |
||
17 | * |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $name; |
||
21 | |||
22 | /** |
||
23 | * Container inside of which an attribute of metadata has not been found |
||
24 | * |
||
25 | * @var MetadataAwareInterface |
||
26 | */ |
||
27 | protected $container; |
||
28 | |||
29 | /** |
||
30 | * MetadataAttributeNotFoundException constructor. |
||
31 | * |
||
32 | * @param MetadataAwareInterface $container |
||
33 | * @param string $name |
||
34 | * @param \Exception | null $previous |
||
35 | */ |
||
36 | 14 | public function __construct(MetadataAwareInterface $container, string $name, \Exception $previous = null) |
|
49 | |||
50 | /** |
||
51 | * Get name of not found attribute of metadata |
||
52 | * |
||
53 | * @return string |
||
54 | */ |
||
55 | 1 | public function getName(): string |
|
59 | |||
60 | /** |
||
61 | * Get container inside of which an attribute of metadata has not been found |
||
62 | * |
||
63 | * @return MetadataAwareInterface |
||
64 | */ |
||
65 | 1 | public function getContainer(): MetadataAwareInterface |
|
69 | } |
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.