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 |
||
14 | class Field extends AbstractAst implements FieldInterface |
||
15 | { |
||
16 | use AstArgumentsTrait; |
||
17 | use AstDirectivesTrait; |
||
18 | |||
19 | /** @var string */ |
||
20 | private $name; |
||
21 | |||
22 | /** @var null|string */ |
||
23 | private $alias = null; |
||
24 | |||
25 | /** |
||
26 | * @param string $name |
||
27 | * @param string $alias |
||
28 | * @param array $arguments |
||
29 | * @param array $directives |
||
30 | * @param Location $location |
||
31 | */ |
||
32 | 69 | View Code Duplication | public function __construct($name, $alias, array $arguments, array $directives, Location $location) |
41 | |||
42 | /** |
||
43 | * @return string |
||
44 | */ |
||
45 | 39 | public function getName() |
|
49 | |||
50 | /** |
||
51 | * @param string $name |
||
52 | */ |
||
53 | 1 | public function setName($name) |
|
57 | |||
58 | /** |
||
59 | * @return null|string |
||
60 | */ |
||
61 | 39 | public function getAlias() |
|
65 | |||
66 | /** |
||
67 | * @param null|string $alias |
||
68 | */ |
||
69 | 1 | public function setAlias($alias) |
|
73 | |||
74 | public function hasFields() |
||
78 | |||
79 | public function getFields() |
||
83 | |||
84 | } |
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.