We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 13 |
Paths | 22 |
Total Lines | 57 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
Tests | 30 |
CRAP Score | 13.0412 |
Changes | 2 | ||
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 | if ($type instanceof InputObjectType) { |
|
85 | 2 | return $this->getTypeClassInstance($type->name) ?: null; |
|
86 | } |
||
87 | 4 | return $data; |
|
88 | } |
||
89 | |||
90 | 4 | if ($type instanceof NonNull) { |
|
91 | $type = $type->getWrappedType(); |
||
92 | } |
||
93 | |||
94 | 4 | if ($multiple) { |
|
95 | return \array_map(function ($data) use ($type, $info) { |
||
96 | 4 | return $this->populateObject($type, $data, false, $info); |
|
97 | 4 | }, $data); |
|
98 | } |
||
99 | |||
100 | 4 | if ($type instanceof EnumType) { |
|
101 | 4 | $instance = $this->getTypeClassInstance($type->name); |
|
102 | 4 | if ($instance) { |
|
103 | 2 | $this->accessor->setValue($instance, 'value', $data); |
|
104 | |||
105 | 2 | return $instance; |
|
106 | } else { |
||
107 | 3 | return $data; |
|
108 | } |
||
109 | 4 | } elseif ($type instanceof InputObjectType) { |
|
110 | 4 | $instance = $this->getTypeClassInstance($type->name); |
|
111 | 4 | if (!$instance) { |
|
112 | return $data; |
||
113 | } |
||
114 | |||
115 | 4 | $fields = $type->getFields(); |
|
116 | |||
117 | 4 | foreach ($fields as $name => $field) { |
|
118 | 4 | $fieldData = $this->accessor->getValue($data, \sprintf('[%s]', $name)); |
|
119 | 4 | $fieldType = $field->getType(); |
|
120 | |||
121 | 4 | if ($fieldType instanceof NonNull) { |
|
122 | 4 | $fieldType = $fieldType->getWrappedType(); |
|
123 | } |
||
124 | |||
125 | 4 | if ($fieldType instanceof ListOfType) { |
|
126 | 4 | $fieldValue = $this->populateObject($fieldType->getWrappedType(), $fieldData, true, $info); |
|
127 | } else { |
||
128 | 4 | $fieldValue = $this->populateObject($fieldType, $fieldData, false, $info); |
|
129 | } |
||
130 | |||
131 | 4 | $this->accessor->setValue($instance, $name, $fieldValue); |
|
132 | } |
||
133 | |||
134 | 4 | return $instance; |
|
135 | } |
||
136 | |||
137 | 4 | return $data; |
|
138 | } |
||
211 |