We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 17 |
| Paths | 86 |
| Total Lines | 72 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 40 |
| CRAP Score | 17 |
| 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 |
||
| 141 | 10 | protected function buildValidationTree(ValidationNode $rootObject, array $constraintMapping, array $args): ValidationNode |
|
| 142 | { |
||
| 143 | 10 | $metadata = new ObjectMetadata($rootObject); |
|
| 144 | |||
| 145 | 10 | $this->applyClassConstraints($metadata, $constraintMapping['class']); |
|
| 146 | |||
| 147 | 10 | foreach ($constraintMapping['properties'] as $property => $params) { |
|
| 148 | 10 | if (!empty($params['cascade']) && isset($args[$property])) { |
|
| 149 | 4 | $options = $params['cascade']; |
|
| 150 | 4 | $type = $this->info->schema->getType($options['referenceType']); |
|
| 151 | |||
| 152 | 4 | if ($options['isCollection']) { |
|
| 153 | 2 | $rootObject->$property = $this->createCollectionNode($args[$property], $type, $rootObject); |
|
| 154 | } else { |
||
| 155 | 4 | $rootObject->$property = $this->createObjectNode($args[$property], $type, $rootObject); |
|
| 156 | } |
||
| 157 | |||
| 158 | 4 | $valid = new Valid(); |
|
| 159 | |||
| 160 | 4 | if (!empty($options['groups'])) { |
|
| 161 | 2 | $valid->groups = $options['groups']; |
|
| 162 | } |
||
| 163 | |||
| 164 | 4 | $metadata->addPropertyConstraint($property, $valid); |
|
| 165 | } else { |
||
| 166 | 10 | $rootObject->$property = $args[$property] ?? null; |
|
| 167 | } |
||
| 168 | |||
| 169 | 10 | foreach ($params ?? [] as $key => $value) { |
|
| 170 | 10 | if (null === $value) { |
|
| 171 | 10 | continue; |
|
| 172 | } |
||
| 173 | |||
| 174 | 10 | switch ($key) { |
|
| 175 | 10 | case 'link': |
|
| 176 | 2 | [$fqcn, $property, $type] = $value; |
|
| 177 | |||
| 178 | 2 | if (!\in_array($fqcn, $this->cachedMetadata)) { |
|
| 179 | 2 | $this->cachedMetadata[$fqcn] = $this->validator->getMetadataFor($fqcn); |
|
| 180 | } |
||
| 181 | |||
| 182 | // Get metadata from the property and it's getters |
||
| 183 | 2 | $propertyMetadata = $this->cachedMetadata[$fqcn]->getPropertyMetadata($property); |
|
| 184 | |||
| 185 | 2 | foreach ($propertyMetadata as $memberMetadata) { |
|
| 186 | // Allow only constraints specified by the "link" matcher |
||
| 187 | 2 | if (self::TYPE_GETTER === $type) { |
|
| 188 | 2 | if (!$memberMetadata instanceof GetterMetadata) { |
|
| 189 | 2 | continue; |
|
| 190 | } |
||
| 191 | 2 | } elseif (self::TYPE_PROPERTY === $type) { |
|
| 192 | 2 | if (!$memberMetadata instanceof PropertyMetadata) { |
|
| 193 | 2 | continue; |
|
| 194 | } |
||
| 195 | } |
||
| 196 | |||
| 197 | 2 | $metadata->addPropertyConstraints($property, $memberMetadata->getConstraints()); |
|
| 198 | } |
||
| 199 | |||
| 200 | 2 | break; |
|
| 201 | 8 | case 'constraints': |
|
| 202 | 8 | $metadata->addPropertyConstraints($property, $value); |
|
| 203 | 8 | break; |
|
| 204 | 4 | case 'cascade': |
|
| 205 | 4 | break; |
|
| 206 | } |
||
| 207 | } |
||
| 208 | } |
||
| 209 | |||
| 210 | 10 | $this->metadataFactory->addMetadata($metadata); |
|
| 211 | |||
| 212 | 10 | return $rootObject; |
|
| 213 | } |
||
| 282 |