Conditions | 10 |
Paths | 12 |
Total Lines | 32 |
Code Lines | 19 |
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 |
||
71 | public function deserializeEnum(DeserializationVisitorInterface $visitor, $data, array $type): ?\UnitEnum |
||
72 | { |
||
73 | $enumType = $type['params'][0]; |
||
74 | if (isset($enumType['name'])) { |
||
75 | $enumType = $enumType['name']; |
||
76 | } else { |
||
77 | trigger_deprecation('jms/serializer', '3.31', "Using enum<'Type'> or similar is deprecated, use enum<Type> instead."); |
||
78 | } |
||
79 | |||
80 | $caseValue = (string) $data; |
||
81 | |||
82 | $ref = new \ReflectionEnum($enumType); |
||
83 | if (isset($type['params'][1]) && 'value' === $type['params'][1] || (!isset($type['params'][1]) && is_a($enumType, \BackedEnum::class, true))) { |
||
84 | if (!is_a($enumType, \BackedEnum::class, true)) { |
||
85 | throw new InvalidMetadataException(sprintf('The type "%s" is not a backed enum, thus you can not use "value" as serialization mode for its value.', $enumType)); |
||
86 | } |
||
87 | |||
88 | if ('int' === $ref->getBackingType()->getName()) { |
||
89 | if (!is_numeric($caseValue)) { |
||
90 | throw new RuntimeException(sprintf('"%s" is not a valid backing value for enum "%s"', $caseValue, $enumType)); |
||
91 | } |
||
92 | |||
93 | $caseValue = (int) $caseValue; |
||
94 | } |
||
95 | |||
96 | return $enumType::from($caseValue); |
||
97 | } else { |
||
98 | if (!$ref->hasCase($caseValue)) { |
||
99 | throw new InvalidMetadataException(sprintf('The type "%s" does not have the case "%s"', $ref->getName(), $caseValue)); |
||
100 | } |
||
101 | |||
102 | return $ref->getCase($caseValue)->getValue(); |
||
103 | } |
||
106 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths