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 |
||
15 | View Code Duplication | final class Image extends AbstractElement implements ParentElementInterface |
|
|
|||
16 | { |
||
17 | public function __construct(AttributeSet $attributes = null, ElementSet $children = null) |
||
23 | |||
24 | public function withAttribute(string $name, string $value = null): Image |
||
34 | |||
35 | public function withChild(ElementInterface $element): Image |
||
39 | |||
40 | public function withAlt(string $alt): Image |
||
44 | |||
45 | public function withCrossOrigin(string $policy = 'anonymous'): Image |
||
49 | |||
50 | public function withHeight(int $pixels): Image |
||
54 | |||
55 | public function withIsMap(): Image |
||
59 | |||
60 | public function withLongDesc(string $urlOrId): Image |
||
64 | |||
65 | public function withSizes(string $sizes): Image |
||
69 | |||
70 | public function withSrc(string $url): Image |
||
74 | |||
75 | public function withSrcSet(string $srcSet): Image |
||
79 | |||
80 | public function withWidth(int $pixels): Image |
||
84 | |||
85 | public function withUseMap(string $id): Image |
||
89 | } |
||
90 |
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.