We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 18 |
Paths | 14 |
Total Lines | 78 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Tests | 40 |
CRAP Score | 18.0047 |
Changes | 1 | ||
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 |
||
117 | 16 | protected function buildValidationTree(ValidationNode $rootObject, array $propertiesMapping, array $classMapping, array $args): ValidationNode |
|
118 | { |
||
119 | 16 | $metadata = new ObjectMetadata($rootObject); |
|
120 | |||
121 | 16 | if (!empty($classMapping)) { |
|
122 | 8 | $this->applyClassConstraints($metadata, $classMapping); |
|
123 | } |
||
124 | |||
125 | 16 | foreach ($propertiesMapping as $property => $params) { |
|
126 | 16 | if (!empty($params['cascade']) && isset($args[$property])) { |
|
127 | 6 | $options = $params['cascade']; |
|
128 | |||
129 | /** @var ObjectType|InputObjectType $type */ |
||
130 | 6 | $type = $options['referenceType']; |
|
131 | |||
132 | 6 | if (null === $type) { |
|
133 | continue; |
||
134 | } |
||
135 | |||
136 | 6 | if ($options['isCollection']) { |
|
137 | 2 | $rootObject->$property = $this->createCollectionNode($args[$property], $type, $rootObject); |
|
138 | } else { |
||
139 | 6 | $rootObject->$property = $this->createObjectNode($args[$property], $type, $rootObject); |
|
140 | } |
||
141 | |||
142 | 6 | $valid = new Valid(); |
|
143 | |||
144 | 6 | if (!empty($options['groups'])) { |
|
145 | 4 | $valid->groups = $options['groups']; |
|
146 | } |
||
147 | |||
148 | 6 | $metadata->addPropertyConstraint($property, $valid); |
|
149 | } else { |
||
150 | 16 | $rootObject->$property = $args[$property] ?? null; |
|
151 | } |
||
152 | |||
153 | 16 | $this->restructureShortForm($params); |
|
154 | |||
155 | 16 | foreach ($params ?? [] as $key => $value) { |
|
156 | switch ($key) { |
||
157 | 16 | case 'link': |
|
158 | 2 | [$fqcn, $property, $type] = $value; |
|
159 | |||
160 | 2 | if (!\in_array($fqcn, $this->cachedMetadata)) { |
|
161 | 2 | $this->cachedMetadata[$fqcn] = $this->validator->getMetadataFor($fqcn); |
|
162 | } |
||
163 | |||
164 | // Get metadata from the property and it's getters |
||
165 | 2 | $propertyMetadata = $this->cachedMetadata[$fqcn]->getPropertyMetadata($property); |
|
166 | |||
167 | 2 | foreach ($propertyMetadata as $memberMetadata) { |
|
168 | // Allow only constraints specified by the "link" matcher |
||
169 | 2 | if (self::TYPE_GETTER === $type) { |
|
170 | 2 | if (!$memberMetadata instanceof GetterMetadata) { |
|
171 | 2 | continue; |
|
172 | } |
||
173 | 2 | } elseif (self::TYPE_PROPERTY === $type) { |
|
174 | 2 | if (!$memberMetadata instanceof PropertyMetadata) { |
|
175 | 2 | continue; |
|
176 | } |
||
177 | } |
||
178 | |||
179 | 2 | $metadata->addPropertyConstraints($property, $memberMetadata->getConstraints()); |
|
180 | } |
||
181 | |||
182 | 2 | break; |
|
183 | 14 | case 'constraints': |
|
184 | 14 | $metadata->addPropertyConstraints($property, $value); |
|
185 | 14 | break; |
|
186 | 6 | case 'cascade': |
|
187 | 6 | break; |
|
188 | } |
||
189 | } |
||
190 | } |
||
191 | |||
192 | 16 | $this->metadataFactory->addMetadata($metadata); |
|
193 | |||
194 | 16 | return $rootObject; |
|
195 | } |
||
274 |