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 |
||
12 | class Media |
||
13 | { |
||
14 | protected $file; |
||
15 | |||
16 | protected $media; |
||
17 | |||
18 | public function __construct(File $file, MediaTypeInterface $media) |
||
23 | |||
24 | public function isFrame(): bool |
||
28 | |||
29 | public function getFile(): File |
||
33 | |||
34 | View Code Duplication | public function getDurationInSeconds(): int |
|
48 | |||
49 | View Code Duplication | public function getDurationInMiliseconds(): float |
|
63 | |||
64 | public function export(): MediaExporter |
||
68 | |||
69 | public function exportForHLS(): HLSPlaylistExporter |
||
73 | |||
74 | public function getFrameFromString(string $timecode): Frame |
||
80 | |||
81 | public function getFrameFromSeconds(float $quantity): Frame |
||
87 | |||
88 | public function getFrameFromTimecode(TimeCode $timecode): Frame |
||
94 | |||
95 | public function addFilter(): Media |
||
107 | |||
108 | protected function selfOrArgument($argument) |
||
112 | |||
113 | public function __invoke(): MediaTypeInterface |
||
117 | |||
118 | public function __clone() |
||
128 | |||
129 | public function __call($method, $parameters) |
||
135 | } |
||
136 |
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.