We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 13 |
Paths | 70 |
Total Lines | 40 |
Code Lines | 24 |
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 |
||
29 | public function guessType(ReflectionClass $reflectionClass, Reflector $reflector, array $filterGraphQLTypes = []): ?string |
||
30 | { |
||
31 | $type = null; |
||
32 | $hasDefaultValue = false; |
||
33 | |||
34 | switch (true) { |
||
35 | case $reflector instanceof ReflectionParameter: |
||
36 | /** @var ReflectionParameter $reflector */ |
||
37 | $hasDefaultValue = $reflector->isDefaultValueAvailable(); |
||
38 | // no break |
||
39 | case $reflector instanceof ReflectionProperty: |
||
40 | /** @var ReflectionProperty $reflector */ |
||
41 | $type = $reflector->hasType() ? $reflector->getType() : null; |
||
42 | |||
43 | break; |
||
44 | case $reflector instanceof ReflectionMethod: |
||
45 | /** @var ReflectionMethod $reflector */ |
||
46 | $type = $reflector->hasReturnType() ? $reflector->getReturnType() : null; |
||
47 | break; |
||
48 | } |
||
49 | /** @var ReflectionNamedType|null $type */ |
||
50 | if (!$type) { |
||
51 | throw new TypeGuessingException('No type-hint'); |
||
52 | } |
||
53 | |||
54 | $sType = $type->getName(); |
||
55 | if ($type->isBuiltin()) { |
||
56 | $gqlType = $this->resolveTypeFromPhpType($sType); |
||
57 | if (null === $gqlType) { |
||
58 | throw new TypeGuessingException(sprintf('No corresponding GraphQL type found for builtin type "%s"', $sType)); |
||
59 | } |
||
60 | } else { |
||
61 | $gqlType = $this->map->resolveType($sType, $filterGraphQLTypes); |
||
62 | if (null === $gqlType) { |
||
63 | throw new TypeGuessingException(sprintf('No corresponding GraphQL %s found for class "%s"', $filterGraphQLTypes ? implode(',', $filterGraphQLTypes) : 'object', $sType)); |
||
64 | } |
||
65 | } |
||
66 | $nullable = $hasDefaultValue || $type->allowsNull(); |
||
67 | |||
68 | return sprintf('%s%s', $gqlType, $nullable ? '' : '!'); |
||
69 | } |
||
71 |