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