| Conditions | 20 |
| Paths | 640 |
| Total Lines | 64 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 179 | private function collapseType(array $originDefinition): ?array |
||
| 180 | { |
||
| 181 | $definition = []; |
||
| 182 | if ($type = $originDefinition['type'] ?? null) { |
||
| 183 | $typeName = $type['name']; |
||
| 184 | if (!empty($type['ofType'] ?? [])) { |
||
| 185 | $typeName = $type['ofType']['name']; |
||
| 186 | $ofType = $type; |
||
| 187 | if (in_array($ofType['kind'], ['NON_NULL', 'LIST'])) { |
||
| 188 | $typeName = '%s'; |
||
| 189 | while ($ofType) { |
||
| 190 | if ($ofType['kind'] === 'NON_NULL') { |
||
| 191 | $typeName = str_replace('%s', '%s!', $typeName); |
||
| 192 | } elseif ($ofType['kind'] === 'LIST') { |
||
| 193 | $typeName = str_replace('%s', '[%s]', $typeName); |
||
| 194 | } else { |
||
| 195 | $typeName = sprintf($typeName, $ofType['name']); |
||
| 196 | break; |
||
| 197 | } |
||
| 198 | $ofType = $ofType['ofType'] ?? null; |
||
| 199 | } |
||
| 200 | } |
||
| 201 | } |
||
| 202 | |||
| 203 | $definition['type'] = $typeName; |
||
| 204 | } |
||
| 205 | |||
| 206 | if ($fields = $originDefinition['fields'] ?? null) { |
||
| 207 | foreach ($fields as $field) { |
||
| 208 | $definition['fields'][$field['name']] = $this->collapseType($field); |
||
| 209 | } |
||
| 210 | } |
||
| 211 | |||
| 212 | if ($inputFields = $originDefinition['inputFields'] ?? null) { |
||
| 213 | foreach ($inputFields as $inputField) { |
||
| 214 | $definition['inputFields'][$inputField['name']] = $this->collapseType($inputField); |
||
| 215 | } |
||
| 216 | } |
||
| 217 | |||
| 218 | if ($args = $originDefinition['args'] ?? null) { |
||
| 219 | foreach ($args as $arg) { |
||
| 220 | $definition['args'][$arg['name']] = $this->collapseType($arg); |
||
| 221 | } |
||
| 222 | } |
||
| 223 | |||
| 224 | if ($possibleTypes = $originDefinition['possibleTypes'] ?? null) { |
||
| 225 | foreach ($possibleTypes as $possibleType) { |
||
| 226 | $definition['possibleTypes'][$possibleType['name']] = $this->collapseType($possibleType); |
||
| 227 | } |
||
| 228 | } |
||
| 229 | |||
| 230 | if ($interfaces = $originDefinition['interfaces'] ?? null) { |
||
| 231 | foreach ($interfaces as $interface) { |
||
| 232 | $definition['interfaces'][] = $interface['name']; |
||
| 233 | } |
||
| 234 | } |
||
| 235 | |||
| 236 | if ($enumValues = $originDefinition['enumValues'] ?? null) { |
||
| 237 | foreach ($enumValues as $enumValue) { |
||
| 238 | $definition['enumValues'][] = $enumValue['name']; |
||
| 239 | } |
||
| 240 | } |
||
| 241 | |||
| 242 | return empty($definition) ? null : $definition; |
||
| 243 | } |
||
| 245 |