Conditions | 10 |
Paths | 9 |
Total Lines | 35 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
63 | public function deserializeEnum(DeserializationVisitorInterface $visitor, $data, array $type): ?\UnitEnum |
||
64 | { |
||
65 | $ref = new \ReflectionEnum($type['params'][0]); |
||
66 | |||
67 | if (isset($type['params'][1]) && 'value' === $type['params'][1]) { |
||
68 | $backingType = $ref->getBackingType(); |
||
69 | |||
70 | if (!$backingType instanceof \ReflectionNamedType) { |
||
71 | throw new InvalidMetadataException(sprintf('The type "%s" is not a backed enum, thus you can not use "value" as serialization mode for its value.', $ref->getName())); |
||
72 | } |
||
73 | |||
74 | $cases = $ref->getCases(); |
||
75 | foreach ($cases as $case) { |
||
76 | $value = $case->getValue(); |
||
77 | $backingTypeName = $backingType->getName(); |
||
78 | |||
79 | if ('int' === $backingTypeName) { |
||
80 | if ($value->value === (int) $data) { |
||
81 | return $value; |
||
82 | } |
||
83 | } elseif ('string' === $backingTypeName) { |
||
84 | if ($value->value === (string) $data) { |
||
85 | return $value; |
||
86 | } |
||
87 | } |
||
88 | } |
||
89 | |||
90 | return null; |
||
91 | } else { |
||
92 | $caseValue = (string) $data; |
||
93 | if (!$ref->hasCase($caseValue)) { |
||
94 | throw new InvalidMetadataException(sprintf('The type "%s" does not have the case "%s"', $ref->getName(), $caseValue)); |
||
95 | } |
||
96 | |||
97 | return $ref->getCase($caseValue)->getValue(); |
||
98 | } |
||
101 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.