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