Conditions | 11 |
Paths | 8 |
Total Lines | 47 |
Code Lines | 26 |
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 |
||
77 | public function deserializeUnion(DeserializationVisitorInterface $visitor, mixed $data, array $type, DeserializationContext $context): mixed |
||
78 | { |
||
79 | if ($data instanceof \SimpleXMLElement) { |
||
80 | throw new RuntimeException('XML deserialisation into union types is not supported yet.'); |
||
81 | } |
||
82 | |||
83 | if (3 === count($type['params'])) { |
||
84 | $lookupField = $type['params'][1]; |
||
85 | if (empty($data[$lookupField])) { |
||
86 | throw new NonVisitableTypeException(sprintf('Union Discriminator Field "%s" not found in data', $lookupField)); |
||
87 | } |
||
88 | |||
89 | $unionMap = $type['params'][2]; |
||
90 | $lookupValue = $data[$lookupField]; |
||
91 | if (empty($unionMap[$lookupValue])) { |
||
92 | throw new NonVisitableTypeException(sprintf('Union Discriminator Map does not contain key "%s"', $lookupValue)); |
||
93 | } |
||
94 | |||
95 | $finalType = [ |
||
96 | 'name' => $unionMap[$lookupValue], |
||
97 | 'params' => [], |
||
98 | ]; |
||
99 | |||
100 | return $context->getNavigator()->accept($data, $finalType); |
||
101 | } |
||
102 | |||
103 | $dataType = gettype($data); |
||
104 | |||
105 | if ( |
||
106 | array_filter( |
||
107 | $type['params'][0], |
||
108 | static fn (array $type): bool => $type['name'] === $dataType || (isset(self::$aliases[$dataType]) && $type['name'] === self::$aliases[$dataType]), |
||
109 | ) |
||
110 | ) { |
||
111 | return $context->getNavigator()->accept($data, [ |
||
112 | 'name' => $dataType, |
||
113 | 'params' => [], |
||
114 | ]); |
||
115 | } |
||
116 | |||
117 | foreach ($type['params'][0] as $possibleType) { |
||
118 | if ($this->isPrimitiveType($possibleType['name']) && $this->testPrimitive($data, $possibleType['name'])) { |
||
119 | return $context->getNavigator()->accept($data, $possibleType); |
||
120 | } |
||
121 | } |
||
122 | |||
123 | throw new NotAcceptableException(); |
||
124 | } |
||
162 |
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