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 |
||
18 | View Code Duplication | final class ExecutedMigrationsList implements Countable |
|
|
|||
19 | { |
||
20 | /** @var ExecutedMigration[] */ |
||
21 | private $items = []; |
||
22 | |||
23 | /** |
||
24 | * @param ExecutedMigration[] $items |
||
25 | */ |
||
26 | 87 | public function __construct(array $items) |
|
30 | |||
31 | /** |
||
32 | * @return ExecutedMigration[] |
||
33 | */ |
||
34 | 31 | public function getItems() : array |
|
38 | |||
39 | 2 | public function getFirst(int $offset = 0) : ExecutedMigration |
|
47 | |||
48 | 24 | public function getLast(int $offset = 0) : ExecutedMigration |
|
57 | |||
58 | 28 | public function count() : int |
|
62 | |||
63 | 46 | public function hasMigration(Version $version) : bool |
|
73 | |||
74 | 5 | public function getMigration(Version $version) : ExecutedMigration |
|
84 | } |
||
85 |
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.