Conditions | 12 |
Paths | 8 |
Total Lines | 36 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
91 | protected function formatInnerField($name = null, $inner = []) |
||
92 | { |
||
93 | if ($inner instanceof BaseAttribute) { |
||
94 | return $inner; |
||
95 | } |
||
96 | |||
97 | if ($inner instanceof AttributeCollection) { |
||
98 | $formattedItems = []; |
||
99 | |||
100 | foreach ($inner->toArray() as $name => $inner) { |
||
101 | $formattedItems[$name] = $this->formatInnerField($inner); |
||
102 | } |
||
103 | |||
104 | return $formattedItems; |
||
105 | } |
||
106 | |||
107 | if (is_scalar($inner) && $this->attributeManager->attributeTypeExists($inner)) { |
||
108 | return $this->attributeManager->createAttribute($inner, $name, [], $this->modelManager); |
||
109 | } |
||
110 | |||
111 | if (is_array($inner) && array_key_exists('type', $inner) && is_scalar($inner['type']) && $this->attributeManager->attributeTypeExists($inner['type'])) { |
||
112 | $type = $inner['type']; |
||
113 | array_forget($inner, 'type'); |
||
114 | return $this->attributeManager->createAttribute($type, $name, $inner, $this->modelManager); |
||
115 | } |
||
116 | |||
117 | if (is_array($inner)) { |
||
118 | $formattedItems = []; |
||
119 | |||
120 | foreach ($inner as $name => $inner) { |
||
121 | $formattedItems[$name] = $this->formatInnerField($inner); |
||
122 | } |
||
123 | |||
124 | return $formattedItems; |
||
125 | } |
||
126 | } |
||
127 | } |
||
128 |
Adding a
@return
annotation 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.