| Conditions | 10 |
| Paths | 40 |
| Total Lines | 40 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| 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); |
||
| 30 | public function create(\stdClass $definition = null): Schema |
||
| 31 | { |
||
| 32 | if (!$definition) { |
||
| 33 | $definition = (object)[]; |
||
| 34 | $definition->type = Schema::TYPE_ANY; |
||
| 35 | } |
||
| 36 | if (!isset($definition->type)) { |
||
| 37 | $definition = clone $definition; |
||
| 38 | $definition->type = Schema::TYPE_STRING; |
||
| 39 | } |
||
| 40 | if (isset($definition->properties)) { |
||
| 41 | $definition->type = 'object'; |
||
| 42 | } |
||
| 43 | |||
| 44 | $index = array_search($definition, $this->definitions); |
||
| 45 | |||
| 46 | if (false === $index) { |
||
| 47 | |||
| 48 | if ($definition->type == Schema::TYPE_OBJECT) { |
||
| 49 | $propertySchemas = (object)[]; |
||
| 50 | |||
| 51 | foreach (isset($definition->properties) ? $definition->properties : [] as $attributeName => $propertyDefinition) { |
||
| 52 | $propertySchemas->$attributeName = $this->create($propertyDefinition); |
||
| 53 | } |
||
| 54 | $schema = new ObjectSchema($definition, $propertySchemas); |
||
| 55 | } elseif ($definition->type == Schema::TYPE_ARRAY) { |
||
| 56 | $itemsSchema = isset($definition->items) ? $this->create($definition->items) : null; |
||
| 57 | $schema = new ArraySchema($definition, $itemsSchema); |
||
| 58 | } else { |
||
| 59 | $schema = new ScalarSchema($definition); |
||
| 60 | } |
||
| 61 | |||
| 62 | $this->definitions[] = $definition; |
||
| 63 | $this->schemas[] = $schema; |
||
| 64 | |||
| 65 | return $schema; |
||
| 66 | } |
||
| 67 | |||
| 68 | return $this->schemas[$index]; |
||
| 69 | } |
||
| 70 | } |
||
| 71 |