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 |
||
15 | class InterfaceType extends AbstractType implements OutputTypeInterface, CompositeTypeInterface, NullableTypeInterface |
||
16 | { |
||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | protected $fields; |
||
21 | |||
22 | /** |
||
23 | * @var callable|null |
||
24 | */ |
||
25 | protected $typeResolver; |
||
26 | |||
27 | /** |
||
28 | * @var \Fubhy\GraphQL\Type\Definition\Types\TypeInterface[] |
||
29 | */ |
||
30 | protected $types = []; |
||
31 | |||
32 | /** |
||
33 | * @var \Fubhy\GraphQL\Type\Definition\FieldDefinition[] |
||
34 | */ |
||
35 | protected $fieldMap; |
||
36 | |||
37 | /** |
||
38 | * Constructor. |
||
39 | * |
||
40 | * @param string $name |
||
41 | * @param array $fields |
||
42 | * @param callable|null $typeResolver |
||
43 | * @param string|null $description |
||
44 | */ |
||
45 | 87 | public function __construct($name, array $fields = [], callable $typeResolver = NULL, $description = NULL) |
|
52 | |||
53 | /** |
||
54 | * {@inheritdoc} |
||
55 | */ |
||
56 | 54 | public function getName() |
|
60 | |||
61 | /** |
||
62 | * {@inheritdoc} |
||
63 | */ |
||
64 | public function getDescription() |
||
68 | |||
69 | /** |
||
70 | * @return \Fubhy\GraphQL\Type\Definition\FieldDefinition[] |
||
71 | */ |
||
72 | 48 | View Code Duplication | public function getFields() |
89 | |||
90 | /** |
||
91 | 51 | * @param array $fields |
|
92 | */ |
||
93 | 51 | public function setFields(array $fields) { |
|
97 | |||
98 | /** |
||
99 | 84 | * {@inheritdoc} |
|
100 | */ |
||
101 | 84 | public function getPossibleTypes() |
|
105 | |||
106 | /** |
||
107 | 3 | * {@inheritdoc} |
|
108 | */ |
||
109 | 3 | public function addPossibleType(ObjectType $type) |
|
113 | |||
114 | /** |
||
115 | 21 | * {@inheritdoc} |
|
116 | */ |
||
117 | 21 | public function isPossibleType(ObjectType $type) |
|
121 | 9 | ||
122 | /** |
||
123 | * {@inheritdoc} |
||
124 | */ |
||
125 | public function resolveType($value) |
||
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.