We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 13 |
Paths | 11 |
Total Lines | 57 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Tests | 27 |
CRAP Score | 13 |
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 |
||
44 | public function guessType(ReflectionClass $reflectionClass, Reflector $reflector, array $filterGraphQLTypes = []): ?string |
||
45 | { |
||
46 | if (!class_exists(Column::class)) { |
||
47 | 52 | throw new TypeGuessingException(sprintf('You must install doctrine/orm package to use this type guesser.')); |
|
48 | } |
||
49 | 52 | ||
50 | 1 | if (!$reflector instanceof ReflectionProperty) { |
|
51 | throw new TypeGuessingException('Doctrine type guesser only apply to properties.'); |
||
52 | } |
||
53 | 52 | ||
54 | /** @var Column|null $columnAnnotation */ |
||
55 | 52 | $columnAnnotation = $this->getAnnotation($reflector, Column::class); |
|
56 | 51 | ||
57 | 51 | if (null !== $columnAnnotation) { |
|
58 | 51 | $type = $this->resolveTypeFromDoctrineType($columnAnnotation->type ?: 'string'); |
|
59 | 51 | $nullable = $columnAnnotation->nullable; |
|
60 | if ($type) { |
||
61 | 2 | return $nullable ? $type : sprintf('%s!', $type); |
|
62 | } else { |
||
63 | throw new TypeGuessingException(sprintf('Unable to auto-guess GraphQL type from Doctrine type "%s"', $columnAnnotation->type)); |
||
64 | } |
||
65 | 52 | } |
|
66 | |||
67 | $associationAnnotations = [ |
||
68 | OneToMany::class => true, |
||
69 | OneToOne::class => false, |
||
70 | ManyToMany::class => true, |
||
71 | ManyToOne::class => false, |
||
72 | 52 | ]; |
|
73 | |||
74 | 52 | foreach ($associationAnnotations as $associationClass => $isMultiple) { |
|
75 | 52 | /** @var OneToMany|OneToOne|ManyToMany|ManyToOne|null $associationAnnotation */ |
|
76 | 51 | $associationAnnotation = $this->getAnnotation($reflector, $associationClass); |
|
77 | 51 | if (null !== $associationAnnotation) { |
|
78 | $target = $this->fullyQualifiedClassName($associationAnnotation->targetEntity, $reflectionClass->getNamespaceName()); |
||
|
|||
79 | 51 | $type = $this->map->resolveType($target, ['type']); |
|
80 | 51 | ||
81 | 51 | if ($type) { |
|
82 | 51 | $isMultiple = $associationAnnotations[get_class($associationAnnotation)]; |
|
83 | if ($isMultiple) { |
||
84 | 51 | return sprintf('[%s]!', $type); |
|
85 | } else { |
||
86 | 51 | $isNullable = false; |
|
87 | 51 | /** @var JoinColumn|null $joinColumn */ |
|
88 | 51 | $joinColumn = $this->getAnnotation($reflector, JoinColumn::class); |
|
89 | if (null !== $joinColumn) { |
||
90 | $isNullable = $joinColumn->nullable; |
||
91 | 51 | } |
|
92 | |||
93 | return sprintf('%s%s', $type, $isNullable ? '' : '!'); |
||
94 | 2 | } |
|
95 | } else { |
||
96 | throw new TypeGuessingException(sprintf('Unable to auto-guess GraphQL type from Doctrine target class "%s" (check if the target class is a GraphQL type itself (with a @Metadata\Type metadata).', $target)); |
||
97 | } |
||
98 | 1 | } |
|
99 | } |
||
100 | throw new TypeGuessingException(sprintf('No Doctrine ORM annotation found.')); |
||
101 | 52 | } |
|
164 |