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 | class ObjectType extends Type implements OutputTypeInterface, CompositeTypeInterface, NullableTypeInterface, UnmodifiedTypeInterface |
||
18 | { |
||
19 | /** |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $fields; |
||
23 | |||
24 | /** |
||
25 | * @var \Fubhy\GraphQL\Type\Definition\Types\InterfaceType[] |
||
26 | */ |
||
27 | protected $interfaces; |
||
28 | |||
29 | /** |
||
30 | * @var \Fubhy\GraphQL\Type\Definition\FieldDefinition[] |
||
31 | */ |
||
32 | protected $fieldMap; |
||
33 | |||
34 | /** |
||
35 | * @var callable|null |
||
36 | */ |
||
37 | protected $isTypeOf; |
||
38 | |||
39 | /** |
||
40 | * Constructor. |
||
41 | * |
||
42 | * @param string $name |
||
43 | * @param array $fields |
||
44 | * @param \Fubhy\GraphQL\Type\Definition\Types\InterfaceType[] $interfaces |
||
45 | * @param callable|null $isTypeOf |
||
46 | * @param string|null $description |
||
47 | */ |
||
48 | 369 | public function __construct($name, array $fields = [], array $interfaces = [], callable $isTypeOf = NULL, $description = NULL) |
|
60 | |||
61 | /** |
||
62 | * @return \Fubhy\GraphQL\Type\Definition\FieldDefinition[] |
||
63 | */ |
||
64 | 306 | View Code Duplication | public function getFields() |
81 | |||
82 | /** |
||
83 | * @param array $fields |
||
84 | */ |
||
85 | public function setFields(array $fields) { |
||
89 | |||
90 | /** |
||
91 | * @param string $field |
||
92 | * |
||
93 | * @return \Fubhy\GraphQL\Type\Definition\FieldDefinition |
||
94 | */ |
||
95 | public function getField($field) |
||
104 | |||
105 | /** |
||
106 | * @return \Fubhy\GraphQL\Type\Definition\Types\InterfaceType[] |
||
107 | */ |
||
108 | 9 | public function getInterfaces() |
|
112 | |||
113 | /** |
||
114 | * @param mixed $value |
||
115 | * |
||
116 | * @return bool|null |
||
117 | */ |
||
118 | public function isTypeOf($value) |
||
122 | } |
||
123 |
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.