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 |
||
36 | private function getEntityConfiguration(ClassMetadata $metadata): ?array |
||
37 | { |
||
38 | $annotation = null; |
||
39 | $auditableAnnotation = null; |
||
40 | $securityAnnotation = null; |
||
41 | $reflection = $metadata->getReflectionClass(); |
||
42 | |||
43 | // Check that we have an Entity annotation or attribute |
||
44 | $attributes = $reflection->getAttributes(Entity::class); |
||
45 | if (\is_array($attributes) && [] !== $attributes) { |
||
46 | $annotation = $attributes[0]->newInstance(); |
||
47 | } |
||
48 | |||
49 | if (null === $annotation) { |
||
50 | return null; |
||
51 | } |
||
52 | |||
53 | // Check that we have an Auditable annotation or attribute |
||
54 | $attributes = $reflection->getAttributes(Auditable::class); |
||
55 | if (\is_array($attributes) && [] !== $attributes) { |
||
56 | $auditableAnnotation = $attributes[0]->newInstance(); |
||
57 | } |
||
58 | |||
59 | if (null === $auditableAnnotation) { |
||
60 | return null; |
||
61 | } |
||
62 | |||
63 | // Check that we have a Security annotation or attribute |
||
64 | $attributes = $reflection->getAttributes(Security::class); |
||
65 | if (\is_array($attributes) && [] !== $attributes) { |
||
66 | $securityAnnotation = $attributes[0]->newInstance(); |
||
67 | } |
||
68 | |||
69 | $roles = null === $securityAnnotation ? null : [Security::VIEW_SCOPE => $securityAnnotation->view]; |
||
70 | |||
71 | // Are there any Ignore annotation or attribute? |
||
72 | $ignoredColumns = $this->getAllProperties($reflection); |
||
73 | |||
74 | return [ |
||
75 | 'ignored_columns' => $ignoredColumns, |
||
76 | 'enabled' => $auditableAnnotation->enabled, |
||
77 | 'roles' => $roles, |
||
78 | ]; |
||
104 |