Conditions | 11 |
Paths | 56 |
Total Lines | 42 |
Code Lines | 27 |
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 | } elseif ($definition->type == Schema::TYPE_ANY) { |
||
59 | $schema = new AnySchema($definition); |
||
60 | } else { |
||
61 | $schema = new ScalarSchema($definition); |
||
62 | } |
||
63 | |||
64 | $this->definitions[] = $definition; |
||
65 | $this->schemas[] = $schema; |
||
66 | |||
67 | return $schema; |
||
68 | } |
||
69 | |||
70 | return $this->schemas[$index]; |
||
71 | } |
||
72 | } |
||
73 |