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 |
||
19 | class EnumType extends Type implements InputTypeInterface, OutputTypeInterface, LeafTypeInterface, NullableTypeInterface, UnmodifiedTypeInterface |
||
20 | { |
||
21 | /** |
||
22 | * @var array |
||
23 | */ |
||
24 | protected $values; |
||
25 | |||
26 | /** |
||
27 | * @var \Fubhy\GraphQL\Type\Definition\EnumValueDefinition[] |
||
28 | */ |
||
29 | protected $valueMap; |
||
30 | |||
31 | /** |
||
32 | * @var \Fubhy\GraphQL\Type\Definition\EnumValueDefinition[] |
||
33 | */ |
||
34 | protected $valueLookup; |
||
35 | |||
36 | /** |
||
37 | * @var \Fubhy\GraphQL\Type\Definition\EnumValueDefinition[] |
||
38 | */ |
||
39 | protected $nameLookup; |
||
40 | |||
41 | /** |
||
42 | * Constructor. |
||
43 | * |
||
44 | * @param string $name |
||
45 | * @param array $values |
||
46 | * @param string|null $description |
||
47 | */ |
||
48 | 75 | public function __construct($name, array $values = [], $description = NULL) |
|
54 | |||
55 | /** |
||
56 | * @return \Fubhy\GraphQL\Type\Definition\EnumValueDefinition[] |
||
57 | */ |
||
58 | 18 | public function getValues() |
|
75 | |||
76 | /** |
||
77 | * @param mixed $value |
||
78 | * |
||
79 | * @return string|null |
||
80 | */ |
||
81 | 27 | public function coerce($value) |
|
86 | |||
87 | /** |
||
88 | * @param \Fubhy\GraphQL\Language\Node $value |
||
89 | * |
||
90 | * @return string|null |
||
91 | */ |
||
92 | public function coerceLiteral(Node $value) |
||
103 | |||
104 | /** |
||
105 | * @return \Fubhy\GraphQL\Type\Definition\EnumValueDefinition[] |
||
106 | */ |
||
107 | 27 | View Code Duplication | protected function getValueLookup() |
118 | |||
119 | /** |
||
120 | * @return \Fubhy\GraphQL\Type\Definition\EnumValueDefinition[] |
||
121 | */ |
||
122 | View Code Duplication | protected function getNameLookup() |
|
133 | } |
||
134 |
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.