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