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