| Conditions | 10 |
| Paths | 7 |
| Total Lines | 30 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 87 | protected function formatInnerField($name = null, $inner = []) |
||
| 88 | { |
||
| 89 | if ($inner instanceof BaseAttribute) { |
||
| 90 | return $inner; |
||
| 91 | } |
||
| 92 | |||
| 93 | if ($inner instanceof AttributeCollection) { |
||
| 94 | $formattedItems = []; |
||
| 95 | |||
| 96 | foreach ($inner->toArray() as $name => $inner) { |
||
| 97 | $formattedItems[$name] = $this->formatInnerField($inner); |
||
| 98 | } |
||
| 99 | |||
| 100 | return $formattedItems; |
||
| 101 | } |
||
| 102 | |||
| 103 | if (is_scalar($inner) && $this->attributeManager->attributeTypeExists($inner)) { |
||
| 104 | return $this->attributeManager->createAttribute($inner, $name, []); |
||
| 105 | } |
||
| 106 | |||
| 107 | if (is_array($inner) && array_key_exists('type', $inner) && $this->attributeManager->attributeTypeExists($inner['type'])) { |
||
| 108 | $type = $inner['type']; |
||
| 109 | array_forget($inner, 'type'); |
||
| 110 | return $this->attributeManager->createAttribute($type, $name, $inner); |
||
| 111 | } |
||
| 112 | |||
| 113 | if (is_array($inner)) { |
||
| 114 | return new AttributeCollection($inner); |
||
| 115 | } |
||
| 116 | } |
||
| 117 | } |
||
| 118 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.