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 | 25 |
| CRAP Score | 11.0069 |
| 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 | private function populateObject(Type $type, $data, bool $multiple, ResolveInfo $info) |
||
| 82 | 2 | { |
|
| 83 | 2 | if (null === $data) { |
|
| 84 | return $data; |
||
| 85 | } |
||
| 86 | 2 | ||
| 87 | 1 | if ($type instanceof NonNull) { |
|
| 88 | $type = $type->getWrappedType(); |
||
| 89 | } |
||
| 90 | 2 | ||
| 91 | if ($multiple) { |
||
| 92 | 2 | return \array_map(function ($data) use ($type, $info) { |
|
| 93 | 2 | return $this->populateObject($type, $data, false, $info); |
|
| 94 | }, $data); |
||
| 95 | } |
||
| 96 | 2 | ||
| 97 | 2 | if ($type instanceof EnumType) { |
|
| 98 | 2 | $instance = $this->getTypeClassInstance($type->name); |
|
| 99 | 1 | if ($instance) { |
|
| 100 | $this->accessor->setValue($instance, 'value', $data); |
||
| 101 | 1 | ||
| 102 | return $instance; |
||
| 103 | 2 | } else { |
|
| 104 | return $data; |
||
| 105 | 2 | } |
|
| 106 | 2 | } elseif ($type instanceof InputObjectType) { |
|
| 107 | 2 | $instance = $this->getTypeClassInstance($type->name); |
|
| 108 | if (!$instance) { |
||
| 109 | return $data; |
||
| 110 | } |
||
| 111 | 2 | ||
| 112 | $fields = $type->getFields(); |
||
| 113 | 2 | ||
| 114 | 2 | foreach ($fields as $name => $field) { |
|
| 115 | $fieldData = $this->accessor->getValue($data, \sprintf('[%s]', $name)); |
||
| 116 | 2 | $fieldType = $field->getType(); |
|
| 117 | 2 | ||
| 118 | if ($fieldType instanceof NonNull) { |
||
| 119 | 2 | $fieldType = $fieldType->getWrappedType(); |
|
| 120 | } |
||
| 121 | |||
| 122 | 2 | if ($fieldType instanceof ListOfType) { |
|
| 123 | $fieldValue = $this->populateObject($fieldType->getWrappedType(), $fieldData, true, $info); |
||
| 124 | } else { |
||
| 125 | 2 | $fieldValue = $this->populateObject($fieldType, $fieldData, false, $info); |
|
| 126 | } |
||
| 127 | 2 | ||
| 128 | $this->accessor->setValue($instance, $name, $fieldValue); |
||
| 129 | } |
||
| 130 | |||
| 131 | return $instance; |
||
| 132 | } else { |
||
| 133 | return $data; |
||
| 134 | } |
||
| 208 |