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 Video 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): Video |
||
34 | |||
35 | public function withChild(ElementInterface $element): Video |
||
39 | |||
40 | public function withControls(): Video |
||
44 | |||
45 | /** |
||
46 | * @param string $policy |
||
47 | * @return Video |
||
48 | * @see https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes |
||
49 | */ |
||
50 | public function withCrossOrigin(string $policy): Video |
||
54 | |||
55 | public function withHeight($height): Video |
||
59 | |||
60 | public function withWidth($width): Video |
||
64 | |||
65 | public function withLoop(): Video |
||
69 | |||
70 | public function withMuted(): Video |
||
74 | |||
75 | public function withPreload(string $preload): Video |
||
79 | |||
80 | public function withPoster(string $url): Video |
||
84 | |||
85 | public function withSrc(string $url): Video |
||
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.