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 | 29 |
CRAP Score | 11.0324 |
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 |
||
67 | 4 | private function populateObject(Type $type, $data, bool $multiple, ResolveInfo $info) |
|
68 | { |
||
69 | 4 | if (null === $data) { |
|
70 | 4 | return null; |
|
71 | } |
||
72 | |||
73 | 4 | if ($type instanceof NonNull) { |
|
74 | $type = $type->getWrappedType(); |
||
75 | } |
||
76 | |||
77 | 4 | if ($multiple) { |
|
78 | 4 | return array_map(function ($data) use ($type, $info) { |
|
79 | 4 | return $this->populateObject($type, $data, false, $info); |
|
80 | 4 | }, $data); |
|
81 | } |
||
82 | |||
83 | 4 | if ($type instanceof EnumType) { |
|
84 | 4 | $instance = $this->getTypeClassInstance($type->name); |
|
85 | 4 | if ($instance) { |
|
86 | 2 | $this->accessor->setValue($instance, 'value', $data); |
|
87 | |||
88 | 2 | return $instance; |
|
89 | } else { |
||
90 | 3 | return $data; |
|
91 | } |
||
92 | 4 | } elseif ($type instanceof InputObjectType) { |
|
93 | 4 | $instance = $this->getTypeClassInstance($type->name); |
|
94 | 4 | if (!$instance) { |
|
95 | return $data; |
||
96 | } |
||
97 | |||
98 | 4 | $fields = $type->getFields(); |
|
99 | |||
100 | 4 | foreach ($fields as $name => $field) { |
|
101 | 4 | $fieldData = $this->accessor->getValue($data, sprintf('[%s]', $name)); |
|
102 | 4 | $fieldType = $field->getType(); |
|
103 | |||
104 | 4 | if ($fieldType instanceof NonNull) { |
|
105 | 4 | $fieldType = $fieldType->getWrappedType(); |
|
106 | } |
||
107 | |||
108 | 4 | if ($fieldType instanceof ListOfType) { |
|
109 | 4 | $fieldValue = $this->populateObject($fieldType->getWrappedType(), $fieldData, true, $info); |
|
110 | } else { |
||
111 | 4 | $fieldValue = $this->populateObject($fieldType, $fieldData, false, $info); |
|
112 | } |
||
113 | |||
114 | 4 | $this->accessor->setValue($instance, $name, $fieldValue); |
|
115 | } |
||
116 | |||
117 | 4 | return $instance; |
|
118 | } else { |
||
119 | 4 | return $data; |
|
120 | } |
||
191 |