| Conditions | 18 |
| Paths | 390 |
| Total Lines | 70 |
| Code Lines | 38 |
| 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 |
||
| 43 | private function getEntityConfiguration(ClassMetadata $metadata): ?array |
||
| 44 | { |
||
| 45 | $annotation = null; |
||
| 46 | $auditableAnnotation = null; |
||
| 47 | $securityAnnotation = null; |
||
| 48 | $annotationProperty = null; |
||
| 49 | $reflection = $metadata->getReflectionClass(); |
||
| 50 | |||
| 51 | // Check that we have an Entity annotation |
||
| 52 | if (\PHP_VERSION_ID >= 80000 && $attributes = $reflection->getAttributes(Entity::class)) { |
||
| 53 | $annotation = $attributes[0]->newInstance(); |
||
| 54 | } elseif (null !== $this->reader) { |
||
| 55 | $annotation = $this->reader->getClassAnnotation($reflection, Entity::class); |
||
| 56 | } |
||
| 57 | |||
| 58 | if (null === $annotation) { |
||
| 59 | return null; |
||
| 60 | } |
||
| 61 | |||
| 62 | // Check that we have an Auditable annotation |
||
| 63 | if (\PHP_VERSION_ID >= 80000 && $attributes = $reflection->getAttributes(Auditable::class)) { |
||
| 64 | /** @var ?Auditable $auditableAnnotation */ |
||
| 65 | $auditableAnnotation = $attributes[0]->newInstance(); |
||
| 66 | } elseif (null !== $this->reader) { |
||
| 67 | /** @var ?Auditable $auditableAnnotation */ |
||
| 68 | $auditableAnnotation = $this->reader->getClassAnnotation($reflection, Auditable::class); |
||
| 69 | } |
||
| 70 | |||
| 71 | if (null === $auditableAnnotation) { |
||
| 72 | return null; |
||
| 73 | } |
||
| 74 | |||
| 75 | // Check that we have an Security annotation |
||
| 76 | if (\PHP_VERSION_ID >= 80000 && $attributes = $reflection->getAttributes(Security::class)) { |
||
| 77 | /** @var ?Security $securityAnnotation */ |
||
| 78 | $securityAnnotation = $attributes[0]->newInstance(); |
||
| 79 | } elseif (null !== $this->reader) { |
||
| 80 | /** @var ?Security $securityAnnotation */ |
||
| 81 | $securityAnnotation = $this->reader->getClassAnnotation($reflection, Security::class); |
||
| 82 | } |
||
| 83 | |||
| 84 | if (null === $securityAnnotation) { |
||
| 85 | $roles = null; |
||
| 86 | } else { |
||
| 87 | $roles = [ |
||
| 88 | Security::VIEW_SCOPE => $securityAnnotation->view, |
||
| 89 | ]; |
||
| 90 | } |
||
| 91 | |||
| 92 | $config = [ |
||
| 93 | 'ignored_columns' => [], |
||
| 94 | 'enabled' => $auditableAnnotation->enabled, |
||
| 95 | 'roles' => $roles, |
||
| 96 | ]; |
||
| 97 | |||
| 98 | // Are there any Ignore annotations? |
||
| 99 | foreach ($reflection->getProperties() as $property) { |
||
| 100 | if (\PHP_VERSION_ID >= 80000 && $attributes = $property->getAttributes(Ignore::class)) { |
||
| 101 | $annotationProperty = $attributes[0]->newInstance(); |
||
| 102 | } elseif (null !== $this->reader) { |
||
| 103 | $annotationProperty = $this->reader->getPropertyAnnotation($property, Ignore::class); |
||
| 104 | } |
||
| 105 | |||
| 106 | if (null !== $annotationProperty) { |
||
| 107 | // TODO: $property->getName() might not be the column name |
||
| 108 | $config['ignored_columns'][] = $property->getName(); |
||
| 109 | } |
||
| 110 | } |
||
| 111 | |||
| 112 | return $config; |
||
| 113 | } |
||
| 115 |