| Conditions | 15 |
| Paths | 80 |
| Total Lines | 92 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 148 | protected function addRefItems( \Aimeos\MShop\Common\Item\ListsRef\Iface $item, array $entry ) |
||
| 149 | { |
||
| 150 | $context = $this->context(); |
||
| 151 | $domain = $item->getResourceType(); |
||
| 152 | $listManager = \Aimeos\MShop::create( $context, $domain . '/lists' ); |
||
| 153 | |||
| 154 | if( isset( $entry['attribute'] ) ) |
||
| 155 | { |
||
| 156 | $manager = \Aimeos\MShop::create( $context, 'attribute' ); |
||
| 157 | |||
| 158 | foreach( $entry['attribute'] as $data ) |
||
| 159 | { |
||
| 160 | $listItem = $listManager->create()->fromArray( $data ); |
||
| 161 | $refItem = $manager->create()->fromArray( $data ); |
||
| 162 | |||
| 163 | try |
||
| 164 | { |
||
| 165 | $manager = \Aimeos\MShop::create( $context, 'attribute' ); |
||
| 166 | $refItem = $manager->find( $refItem->getCode(), [], $domain, $refItem->getType() ); |
||
| 167 | } |
||
| 168 | catch( \Exception $e ) { ; } // attribute doesn't exist yet |
||
| 169 | |||
| 170 | $refItem = $this->addRefItems( $refItem, $data ); |
||
| 171 | $item->addListItem( 'attribute', $listItem, $refItem ); |
||
| 172 | } |
||
| 173 | } |
||
| 174 | |||
| 175 | foreach( ['media', 'price', 'text'] as $refDomain ) |
||
| 176 | { |
||
| 177 | if( isset( $entry[$refDomain] ) ) |
||
| 178 | { |
||
| 179 | $manager = \Aimeos\MShop::create( $context, $refDomain ); |
||
| 180 | |||
| 181 | foreach( $entry[$refDomain] as $data ) |
||
| 182 | { |
||
| 183 | $listItem = $listManager->create()->fromArray( $data ); |
||
| 184 | $refItem = $manager->create()->fromArray( $data ); |
||
| 185 | |||
| 186 | if( isset( $data['property'] ) ) |
||
| 187 | { |
||
| 188 | foreach( (array) $data['property'] as $property ) |
||
| 189 | { |
||
| 190 | $propItem = $manager->createPropertyItem()->fromArray( $property ); |
||
| 191 | $refItem->addPropertyItem( $propItem ); |
||
| 192 | } |
||
| 193 | } |
||
| 194 | |||
| 195 | $item->addListItem( $refDomain, $listItem, $refItem ); |
||
| 196 | } |
||
| 197 | } |
||
| 198 | } |
||
| 199 | |||
| 200 | if( isset( $entry['product'] ) ) |
||
| 201 | { |
||
| 202 | $manager = \Aimeos\MShop::create( $context, 'product' ); |
||
| 203 | |||
| 204 | foreach( $entry['product'] as $data ) |
||
| 205 | { |
||
| 206 | $listItem = $listManager->create()->fromArray( $data ); |
||
| 207 | $listItem->setRefId( $manager->find( $data['product.code'] )->getId() ); |
||
| 208 | |||
| 209 | $item->addListItem( 'product', $listItem ); |
||
| 210 | } |
||
| 211 | } |
||
| 212 | |||
| 213 | if( isset( $entry['catalog'] ) ) |
||
| 214 | { |
||
| 215 | $manager = \Aimeos\MShop::create( $context, 'catalog' ); |
||
| 216 | |||
| 217 | foreach( $entry['catalog'] as $data ) |
||
| 218 | { |
||
| 219 | $listItem = $listManager->create()->fromArray( $data ); |
||
| 220 | $listItem->setRefId( $manager->find( $data['catalog.code'] )->getId() ); |
||
| 221 | |||
| 222 | $item->addListItem( 'catalog', $listItem ); |
||
| 223 | } |
||
| 224 | } |
||
| 225 | |||
| 226 | if( isset( $entry['supplier'] ) ) |
||
| 227 | { |
||
| 228 | $manager = \Aimeos\MShop::create( $context, 'supplier' ); |
||
| 229 | |||
| 230 | foreach( $entry['supplier'] as $data ) |
||
| 231 | { |
||
| 232 | $listItem = $listManager->create()->fromArray( $data ); |
||
| 233 | $listItem->setRefId( $manager->find( $data['supplier.code'] )->getId() ); |
||
| 234 | |||
| 235 | $item->addListItem( 'supplier', $listItem ); |
||
| 236 | } |
||
| 237 | } |
||
| 238 | |||
| 239 | return $item; |
||
| 240 | } |
||
| 287 |