We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 10 |
Paths | 17 |
Total Lines | 48 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Tests | 26 |
CRAP Score | 10.005 |
Changes | 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 |
||
80 | 3 | private function populateObject(Type $type, $data, bool $multiple, ResolveInfo $info) |
|
81 | { |
||
82 | 3 | if (null === $data) { |
|
83 | 3 | return $data; |
|
84 | } |
||
85 | |||
86 | 3 | if ($type instanceof NonNull) { |
|
87 | 1 | $type = $type->getWrappedType(); |
|
88 | } |
||
89 | |||
90 | 3 | if ($multiple) { |
|
91 | return \array_map(function ($data) use ($type, $info) { |
||
92 | 3 | return $this->populateObject($type, $data, false, $info); |
|
93 | 3 | }, $data); |
|
94 | } |
||
95 | |||
96 | 3 | if ($type instanceof EnumType) { |
|
97 | 3 | $instance = $this->getTypeClassInstance($type->name); |
|
98 | 3 | if ($instance) { |
|
99 | 1 | $this->accessor->setValue($instance, 'value', $data); |
|
100 | |||
101 | 1 | return $instance; |
|
102 | } else { |
||
103 | 3 | return $data; |
|
104 | } |
||
105 | 3 | } elseif ($type instanceof InputObjectType) { |
|
106 | 3 | $instance = $this->getTypeClassInstance($type->name); |
|
107 | 3 | if (!$instance) { |
|
108 | return $data; |
||
109 | } |
||
110 | |||
111 | 3 | $fields = $type->getFields(); |
|
112 | |||
113 | 3 | foreach ($fields as $name => $field) { |
|
114 | 3 | $fieldData = $this->accessor->getValue($data, \sprintf('[%s]', $name)); |
|
115 | |||
116 | 3 | if ($field->getType() instanceof ListOfType) { |
|
117 | 3 | $fieldValue = $this->populateObject($field->getType()->getWrappedType(), $fieldData, true, $info); |
|
118 | } else { |
||
119 | 3 | $fieldValue = $this->populateObject($field->getType(), $fieldData, false, $info); |
|
120 | } |
||
121 | |||
122 | 3 | $this->accessor->setValue($instance, $name, $fieldValue); |
|
123 | } |
||
124 | |||
125 | 3 | return $instance; |
|
126 | } else { |
||
127 | 3 | return $data; |
|
128 | } |
||
205 |