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 SchemaConfigurator implements SchemaConfiguratorInterface |
||
13 | { |
||
14 | const ID = 'id'; |
||
15 | const USER = 'user_id'; |
||
16 | const NAME = 'name'; |
||
17 | const QUERY = 'query'; |
||
18 | |||
19 | /** |
||
20 | * @var StringLiteral |
||
21 | */ |
||
22 | private $tableName; |
||
23 | |||
24 | /** |
||
25 | * SchemaConfigurator constructor. |
||
26 | * @param StringLiteral $tableName |
||
27 | */ |
||
28 | public function __construct(StringLiteral $tableName) |
||
32 | |||
33 | /** |
||
34 | * @inheritdoc |
||
35 | */ |
||
36 | View Code Duplication | public function configure(AbstractSchemaManager $schemaManager) |
|
46 | |||
47 | /** |
||
48 | * @param Schema $schema |
||
49 | * @param StringLiteral $tableName |
||
50 | * @return Table |
||
51 | */ |
||
52 | private function createTable(Schema $schema, StringLiteral $tableName) |
||
76 | } |
||
77 |
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.