We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 17 |
| Paths | 162 |
| Total Lines | 74 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 39 |
| CRAP Score | 17 |
| Changes | 2 | ||
| Bugs | 1 | 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 ($options['isCollection']) { |
|
| 133 | 2 | $rootObject->$property = $this->createCollectionNode($args[$property], $type, $rootObject); |
|
| 134 | } else { |
||
| 135 | 6 | $rootObject->$property = $this->createObjectNode($args[$property], $type, $rootObject); |
|
| 136 | } |
||
| 137 | |||
| 138 | 6 | $valid = new Valid(); |
|
| 139 | |||
| 140 | 6 | if (!empty($options['groups'])) { |
|
| 141 | 4 | $valid->groups = $options['groups']; |
|
| 142 | } |
||
| 143 | |||
| 144 | 6 | $metadata->addPropertyConstraint($property, $valid); |
|
| 145 | } else { |
||
| 146 | 16 | $rootObject->$property = $args[$property] ?? null; |
|
| 147 | } |
||
| 148 | |||
| 149 | 16 | $this->restructureShortForm($params); |
|
| 150 | |||
| 151 | 16 | foreach ($params ?? [] as $key => $value) { |
|
| 152 | switch ($key) { |
||
| 153 | 16 | case 'link': |
|
| 154 | 2 | [$fqcn, $property, $type] = $value; |
|
| 155 | |||
| 156 | 2 | if (!\in_array($fqcn, $this->cachedMetadata)) { |
|
| 157 | 2 | $this->cachedMetadata[$fqcn] = $this->validator->getMetadataFor($fqcn); |
|
| 158 | } |
||
| 159 | |||
| 160 | // Get metadata from the property and it's getters |
||
| 161 | 2 | $propertyMetadata = $this->cachedMetadata[$fqcn]->getPropertyMetadata($property); |
|
| 162 | |||
| 163 | 2 | foreach ($propertyMetadata as $memberMetadata) { |
|
| 164 | // Allow only constraints specified by the "link" matcher |
||
| 165 | 2 | if (self::TYPE_GETTER === $type) { |
|
| 166 | 2 | if (!$memberMetadata instanceof GetterMetadata) { |
|
| 167 | 2 | continue; |
|
| 168 | } |
||
| 169 | 2 | } elseif (self::TYPE_PROPERTY === $type) { |
|
| 170 | 2 | if (!$memberMetadata instanceof PropertyMetadata) { |
|
| 171 | 2 | continue; |
|
| 172 | } |
||
| 173 | } |
||
| 174 | |||
| 175 | 2 | $metadata->addPropertyConstraints($property, $memberMetadata->getConstraints()); |
|
| 176 | } |
||
| 177 | |||
| 178 | 2 | break; |
|
| 179 | 14 | case 'constraints': |
|
| 180 | 14 | $metadata->addPropertyConstraints($property, $value); |
|
| 181 | 14 | break; |
|
| 182 | 6 | case 'cascade': |
|
| 183 | 6 | break; |
|
| 184 | } |
||
| 185 | } |
||
| 186 | } |
||
| 187 | |||
| 188 | 16 | $this->metadataFactory->addMetadata($metadata); |
|
| 189 | |||
| 190 | 16 | return $rootObject; |
|
| 191 | } |
||
| 270 |