| Conditions | 15 | 
| Paths | 18 | 
| Total Lines | 65 | 
| Code Lines | 46 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 1 | 
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 | ||
| 138 | private function createSchemaRecursive(string $resourceClass, string $operation, array $groups, int $recursion = 0): Schema | ||
| 139 |     { | ||
| 140 | $cacheKey = $this->getCacheKey($resourceClass, $operation, $groups) . ',' . $recursion; | ||
| 141 |         if (isset($this->alreadyDefined[$cacheKey])) { | ||
| 142 | return $this->alreadyDefined[$cacheKey]; | ||
| 143 | } | ||
| 144 | |||
| 145 |         foreach ($this->predefined as $className => $schema) { | ||
| 146 |             if (is_a($resourceClass, $className, true)) { | ||
| 147 | $this->alreadyDefined[$cacheKey] = $schema; | ||
| 148 | |||
| 149 | return $this->alreadyDefined[$cacheKey]; | ||
| 150 | } | ||
| 151 | } | ||
| 152 | |||
| 153 |         if ($predefinedSchema = $this->runCallbacks($cacheKey, $resourceClass, $operation, $groups, $recursion)) { | ||
| 154 | return $this->alreadyDefined[$cacheKey] = $predefinedSchema; | ||
| 155 | } | ||
| 156 | $refl = new ReflectionClass($resourceClass); | ||
| 157 | $schema = new Schema([ | ||
| 158 | 'type' => 'object', | ||
| 159 | 'properties' => [], | ||
| 160 | 'title' => $refl->getShortName(), | ||
| 161 |             'description' => $refl->getShortName() . ' ' . $operation . ' for groups ' . implode(', ', $groups), | ||
| 162 | ]); | ||
| 163 |         if ($recursion > 3) { | ||
| 164 | return $this->alreadyDefined[$cacheKey] = $schema; | ||
| 165 | } | ||
| 166 | $objectAccess = $this->filterObjectAccess($this->objectAccess, $resourceClass, $groups); | ||
| 167 |         switch ($operation) { | ||
| 168 | case 'post': | ||
| 169 | $constructorArgs = $objectAccess->getConstructorArguments($refl); | ||
| 170 |                 foreach ($constructorArgs as $key => $type) { | ||
| 171 | $fieldName = $this->nameConverter->normalize($key); | ||
| 172 | $schema->properties[$fieldName] = $this->convertTypeToSchema($type, $operation, $groups, $recursion + 1); | ||
| 173 | $description = $objectAccess->getDescription($refl, $fieldName, false); | ||
| 174 |                     if ($description) { | ||
| 175 | $schema->properties[$fieldName]->description = $description; | ||
| 176 | } | ||
| 177 | } | ||
| 178 | // FALLTHROUGH | ||
| 179 | case 'put': | ||
| 180 | $setterFields = $objectAccess->getSetterFields($refl); | ||
| 181 |                 foreach ($setterFields as $setterField) { | ||
| 182 | $fieldName = $this->nameConverter->normalize($setterField); | ||
| 183 | $schema->properties[$fieldName] = $this->convertTypesToSchema($objectAccess->getSetterTypes($refl, $setterField), $operation, $groups, $recursion); | ||
| 184 | $description = $objectAccess->getDescription($refl, $fieldName, false); | ||
| 185 |                     if ($description) { | ||
| 186 | $schema->properties[$fieldName]->description = $description; | ||
| 187 | } | ||
| 188 | } | ||
| 189 | break; | ||
| 190 | case 'get': | ||
| 191 | $getterFields = $objectAccess->getGetterFields($refl); | ||
| 192 |                 foreach ($getterFields as $getterField) { | ||
| 193 | $fieldName = $this->nameConverter->normalize($getterField); | ||
| 194 | $schema->properties[$fieldName] = $this->convertTypesToSchema($objectAccess->getGetterTypes($refl, $getterField), $operation, $groups, $recursion); | ||
| 195 | $description = $objectAccess->getDescription($refl, $fieldName, true); | ||
| 196 |                     if ($description) { | ||
| 197 | $schema->properties[$fieldName]->description = $description; | ||
| 198 | } | ||
| 199 | } | ||
| 200 | break; | ||
| 201 | } | ||
| 202 | return $this->alreadyDefined[$cacheKey] = $schema; | ||
| 203 | } | ||
| 236 |