Conditions | 6 |
Paths | 8 |
Total Lines | 62 |
Code Lines | 23 |
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 |
||
137 | protected function getItems( \Aimeos\MW\View\Iface $view, ServerRequestInterface $request, ResponseInterface $response ) |
||
138 | { |
||
139 | /** client/jsonapi/attribute/types |
||
140 | * List of attribute types that should be displayed in this order in the catalog filter |
||
141 | * |
||
142 | * The attribute section in the catalog filter component can display |
||
143 | * all attributes a visitor can use to reduce the listed products |
||
144 | * to those that contains one or more attributes. By default, all |
||
145 | * available attributes will be displayed and ordered by their |
||
146 | * attribute type. |
||
147 | * |
||
148 | * With this setting, you can limit the attribute types to only thoses |
||
149 | * whose names are part of the setting value. Furthermore, a particular |
||
150 | * order for the attribute types can be enforced that is different |
||
151 | * from the standard order. |
||
152 | * |
||
153 | * @param array List of attribute type codes |
||
154 | * @since 2017.03 |
||
155 | * @category Developer |
||
156 | */ |
||
157 | $attrTypes = $this->getContext()->getConfig()->get( 'client/jsonapi/attribute/types', [] ); |
||
158 | |||
159 | $total = 0; |
||
160 | $attrMap = []; |
||
161 | |||
162 | $ref = $view->param( 'include', [] ); |
||
163 | |||
164 | if( is_string( $ref ) ) { |
||
165 | $ref = explode( ',', $ref ); |
||
166 | } |
||
167 | |||
168 | $cntl = \Aimeos\Controller\Frontend\Factory::createController( $this->getContext(), 'attribute' ); |
||
169 | |||
170 | $filter = $cntl->createFilter(); |
||
171 | $filter = $this->initCriteriaConditions( $filter, $view->param() ); |
||
172 | $filter = $cntl->addFilterTypes( $filter, $attrTypes ); |
||
173 | |||
174 | $items = $cntl->searchItems( $filter, $ref, $total ); |
||
175 | |||
176 | foreach( $items as $id => $item ) { |
||
177 | $attrMap[$item->getType()][$id] = $item; |
||
178 | } |
||
179 | |||
180 | if( !empty( $attrTypes ) ) |
||
181 | { |
||
182 | $sorted = []; |
||
183 | |||
184 | foreach( $attrTypes as $type ) |
||
185 | { |
||
186 | if( isset( $attrMap[$type] ) ) { |
||
187 | $sorted = array_merge( $sorted, $attrMap[$type] ); |
||
188 | } |
||
189 | } |
||
190 | |||
191 | $items = $sorted; |
||
192 | } |
||
193 | |||
194 | $view->items = $items; |
||
195 | $view->total = $total; |
||
196 | |||
197 | return $response; |
||
198 | } |
||
199 | } |
||
200 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.