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