| Conditions | 17 |
| Paths | 16 |
| Total Lines | 68 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 46 | private static function warmupType(Webonyx\Type $type, array &$allTypes): void |
||
| 47 | { |
||
| 48 | if ($type instanceof Webonyx\WrappingType) { |
||
| 49 | self::warmupType($type->getInnermostType(), $allTypes); |
||
| 50 | |||
| 51 | return; |
||
| 52 | } |
||
| 53 | assert($type instanceof Webonyx\NamedType); |
||
| 54 | |||
| 55 | $name = $type->name; |
||
| 56 | if (isset($allTypes[$name])) { |
||
| 57 | return; |
||
| 58 | } |
||
| 59 | |||
| 60 | $allTypes[$name] = true; |
||
| 61 | |||
| 62 | if ($type instanceof Webonyx\EnumType) { |
||
| 63 | $enumValues = $type->getValues(); |
||
| 64 | if (is_callable($type->config['values'])) { |
||
| 65 | $values = []; |
||
| 66 | foreach ($enumValues as $value) { |
||
| 67 | $values[$value->name] = [ |
||
| 68 | 'value' => $value->value, |
||
| 69 | 'description' => $value->description, |
||
| 70 | 'deprecationReason' => $value->deprecationReason, |
||
| 71 | ]; |
||
| 72 | } |
||
| 73 | $type->config['values'] = $values; |
||
| 74 | } |
||
| 75 | return; |
||
| 76 | } |
||
| 77 | |||
| 78 | if ($type instanceof Webonyx\UnionType) { |
||
| 79 | $type->config['types'] = $type->getTypes(); |
||
| 80 | foreach ($type->config['types'] as $member) { |
||
| 81 | self::warmupType($member, $allTypes); |
||
| 82 | } |
||
| 83 | return; |
||
| 84 | } |
||
| 85 | |||
| 86 | if ($type instanceof Webonyx\InputObjectType) { |
||
| 87 | $type->config['fields'] = $type->getFields(); |
||
| 88 | foreach ($type->config['fields'] as $field) { |
||
| 89 | self::warmupType($field->getType(), $allTypes); |
||
| 90 | } |
||
| 91 | return; |
||
| 92 | } |
||
| 93 | |||
| 94 | if ($type instanceof Webonyx\ImplementingType) { |
||
| 95 | $interfaces = $type->getInterfaces(); |
||
| 96 | foreach ($interfaces as $interface) { |
||
| 97 | self::warmupType($interface, $allTypes); |
||
| 98 | } |
||
| 99 | assert($type instanceof Webonyx\ObjectType || $type instanceof Webonyx\InterfaceType); |
||
| 100 | $type->config['interfaces'] = $interfaces; |
||
| 101 | } |
||
| 102 | |||
| 103 | if ($type instanceof Webonyx\HasFieldsType) { |
||
| 104 | $fields = $type->getFields(); |
||
| 105 | foreach ($fields as $field) { |
||
| 106 | foreach ($field->args as $arg) { |
||
| 107 | self::warmupType($arg->config['type'] = $arg->getType(), $allTypes); |
||
| 108 | } |
||
| 109 | self::warmupType($field->getType(), $allTypes); |
||
| 110 | } |
||
| 111 | |||
| 112 | assert($type instanceof Webonyx\ObjectType || $type instanceof Webonyx\InterfaceType); |
||
| 113 | $type->config['fields'] = $fields; |
||
| 114 | } |
||
| 117 |