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