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 |
||
| 17 | View Code Duplication | class ProgramDateTimeTag extends AbstractTag |
|
|
|
|||
| 18 | { |
||
| 19 | use SingleValueTagTrait; |
||
| 20 | |||
| 21 | const TAG_IDENTIFIER = '#EXT-X-PROGRAM-DATE-TIME'; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var string Absolute date and/or time of the first sample of the Media Segment in ISO_8601 format |
||
| 25 | */ |
||
| 26 | private $programDateTime; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @param string $programDateTime |
||
| 30 | * @return $this |
||
| 31 | */ |
||
| 32 | public function setProgramDateTime($programDateTime) |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @return string |
||
| 41 | */ |
||
| 42 | public function getProgramDateTime() |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @return string |
||
| 49 | */ |
||
| 50 | 1 | public function dump() |
|
| 54 | |||
| 55 | /** |
||
| 56 | * @param string $line |
||
| 57 | */ |
||
| 58 | protected function read($line) |
||
| 62 | } |
||
| 63 |
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.