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