| Conditions | 10 |
| Paths | 22 |
| Total Lines | 42 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 39 | private function getEntityConfiguration(ClassMetadata $metadata): ?array |
||
| 40 | { |
||
| 41 | $annotation = null; |
||
| 42 | $auditableAnnotation = null; |
||
| 43 | $securityAnnotation = null; |
||
| 44 | $reflection = $metadata->getReflectionClass(); |
||
| 45 | |||
| 46 | // Check that we have an Entity annotation or attribute |
||
| 47 | $attributes = $reflection->getAttributes(Entity::class); |
||
| 48 | if (\is_array($attributes) && [] !== $attributes) { |
||
| 49 | $annotation = $attributes[0]->newInstance(); |
||
| 50 | } |
||
| 51 | |||
| 52 | if (!$annotation instanceof \Doctrine\ORM\Mapping\Entity) { |
||
| 53 | return null; |
||
| 54 | } |
||
| 55 | |||
| 56 | // Check that we have an Auditable annotation or attribute |
||
| 57 | $attributes = $reflection->getAttributes(Auditable::class); |
||
| 58 | if (\is_array($attributes) && [] !== $attributes) { |
||
| 59 | $auditableAnnotation = $attributes[0]->newInstance(); |
||
| 60 | } |
||
| 61 | |||
| 62 | if (!$auditableAnnotation instanceof \DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable) { |
||
| 63 | return null; |
||
| 64 | } |
||
| 65 | |||
| 66 | // Check that we have a Security annotation or attribute |
||
| 67 | $attributes = $reflection->getAttributes(Security::class); |
||
| 68 | if (\is_array($attributes) && [] !== $attributes) { |
||
| 69 | $securityAnnotation = $attributes[0]->newInstance(); |
||
| 70 | } |
||
| 71 | |||
| 72 | $roles = $securityAnnotation instanceof \DH\Auditor\Provider\Doctrine\Auditing\Annotation\Security ? [Security::VIEW_SCOPE => $securityAnnotation->view] : null; |
||
| 73 | |||
| 74 | // Are there any Ignore annotation or attribute? |
||
| 75 | $ignoredColumns = $this->getAllProperties($reflection); |
||
| 76 | |||
| 77 | return [ |
||
| 78 | 'ignored_columns' => $ignoredColumns, |
||
| 79 | 'enabled' => $auditableAnnotation->enabled, |
||
| 80 | 'roles' => $roles, |
||
| 81 | ]; |
||
| 107 |