We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 11 |
Paths | 21 |
Total Lines | 53 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Tests | 28 |
CRAP Score | 11.0359 |
Changes | 1 | ||
Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
81 | 4 | private function populateObject(Type $type, $data, bool $multiple, ResolveInfo $info) |
|
82 | { |
||
83 | 4 | if (null === $data) { |
|
84 | 4 | return $data; |
|
85 | } |
||
86 | |||
87 | 4 | if ($type instanceof NonNull) { |
|
88 | $type = $type->getWrappedType(); |
||
89 | } |
||
90 | |||
91 | 4 | if ($multiple) { |
|
92 | return \array_map(function ($data) use ($type, $info) { |
||
93 | 4 | return $this->populateObject($type, $data, false, $info); |
|
94 | 4 | }, $data); |
|
95 | } |
||
96 | |||
97 | 4 | if ($type instanceof EnumType) { |
|
98 | 4 | $instance = $this->getTypeClassInstance($type->name); |
|
99 | 4 | if ($instance) { |
|
100 | 2 | $this->accessor->setValue($instance, 'value', $data); |
|
101 | |||
102 | 2 | return $instance; |
|
103 | } else { |
||
104 | 3 | return $data; |
|
105 | } |
||
106 | 4 | } elseif ($type instanceof InputObjectType) { |
|
107 | 4 | $instance = $this->getTypeClassInstance($type->name); |
|
108 | 4 | if (!$instance) { |
|
109 | return $data; |
||
110 | } |
||
111 | |||
112 | 4 | $fields = $type->getFields(); |
|
113 | |||
114 | 4 | foreach ($fields as $name => $field) { |
|
115 | 4 | $fieldData = $this->accessor->getValue($data, \sprintf('[%s]', $name)); |
|
116 | 4 | $fieldType = $field->getType(); |
|
117 | |||
118 | 4 | if ($fieldType instanceof NonNull) { |
|
119 | 4 | $fieldType = $fieldType->getWrappedType(); |
|
120 | } |
||
121 | |||
122 | 4 | if ($fieldType instanceof ListOfType) { |
|
123 | 4 | $fieldValue = $this->populateObject($fieldType->getWrappedType(), $fieldData, true, $info); |
|
124 | } else { |
||
125 | 4 | $fieldValue = $this->populateObject($fieldType, $fieldData, false, $info); |
|
126 | } |
||
127 | |||
128 | 4 | $this->accessor->setValue($instance, $name, $fieldValue); |
|
129 | } |
||
130 | |||
131 | 4 | return $instance; |
|
132 | } else { |
||
133 | 4 | return $data; |
|
134 | } |
||
208 |