| Conditions | 13 |
| Paths | 7 |
| Total Lines | 51 |
| Lines | 16 |
| Ratio | 31.37 % |
| 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 declare(strict_types=1); |
||
| 28 | public function create(Schema $schema, ProcessorBuilder $builder) |
||
| 29 | { |
||
| 30 | if (!$this->supports($schema)) { |
||
| 31 | return null; |
||
| 32 | } |
||
| 33 | |||
| 34 | /** @var ObjectSchema $objectSchema */ |
||
| 35 | $objectSchema = $schema; |
||
| 36 | $processor = $this->instantiate($objectSchema, $builder); |
||
| 37 | |||
| 38 | // TODO: Handle multiple roots |
||
| 39 | if ($objectSchema->hasComplexType()) { |
||
| 40 | $root = $objectSchema->getComplexType(); |
||
| 41 | |||
| 42 | // Recurse up to find root |
||
| 43 | while ($parents = $root->getParents()) { |
||
| 44 | $root = $parents[0]; |
||
| 45 | } |
||
| 46 | |||
| 47 | // Add schema of all children up to root |
||
| 48 | $descend = function (ComplexType $complexType) use (&$descend, $builder, $processor) { |
||
| 49 | |||
| 50 | View Code Duplication | foreach ($complexType->getSchema()->getPropertySchemas() as $propertyName => $propertySchema) { |
|
| 51 | if ($propertySchema instanceof ObjectSchema && $propertySchema->getXType() !== null && !$propertySchema->hasComplexType()) { |
||
| 52 | throw new \LogicException("ComplexType never resolved"); |
||
| 53 | } |
||
| 54 | $propertyProcessor = $builder->build($propertySchema); |
||
| 55 | |||
| 56 | $processor->setPropertyProcessor($propertyName, $propertyProcessor); |
||
| 57 | } |
||
| 58 | |||
| 59 | foreach ($complexType->getChildren() as $child) { |
||
| 60 | $descend($child); |
||
| 61 | } |
||
| 62 | }; |
||
| 63 | |||
| 64 | $descend($root); |
||
| 65 | } |
||
| 66 | |||
| 67 | |||
| 68 | View Code Duplication | foreach ($objectSchema->getPropertySchemas() as $propertyName => $propertySchema) { |
|
| 69 | if ($propertySchema instanceof ObjectSchema && $propertySchema->getXType() !== null && !$propertySchema->hasComplexType()) { |
||
| 70 | throw new \LogicException("ComplexType never resolved"); |
||
| 71 | } |
||
| 72 | $propertyProcessor = $builder->build($propertySchema); |
||
| 73 | |||
| 74 | $processor->setPropertyProcessor($propertyName, $propertyProcessor); |
||
| 75 | } |
||
| 76 | |||
| 77 | return $processor; |
||
| 78 | } |
||
| 79 | |||
| 98 |