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