| Conditions | 10 |
| Paths | 36 |
| Total Lines | 59 |
| Code Lines | 35 |
| 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 |
||
| 43 | public function process( \Aimeos\MShop\Common\Item\Iface $item, \DOMNode $node ) |
||
| 44 | { |
||
| 45 | \Aimeos\MW\Common\Base::checkClass( \Aimeos\MShop\Common\Item\ListRef\Iface::class, $item ); |
||
| 46 | |||
| 47 | $listManager = \Aimeos\MShop::create( $this->getContext(), 'catalog/lists' ); |
||
| 48 | |||
| 49 | $search = $listManager->createSearch()->setSlice( 0, 10000 ); |
||
| 50 | $search->setConditions( $search->combine( '&&', [ |
||
| 51 | $search->compare( '==', 'catalog.lists.domain', 'product' ), |
||
| 52 | $search->compare( '==', 'catalog.lists.refid', $item->getId() ), |
||
| 53 | ] ) ); |
||
| 54 | |||
| 55 | $listItems = $listManager->searchItems( $search ); |
||
| 56 | $catItems = $this->getCatalogItems( $node ); |
||
| 57 | $map = []; |
||
| 58 | |||
| 59 | foreach( $listItems as $listItem ) { |
||
| 60 | $map[$listItem->getParentId()][$listItem->getType()] = $listItem; |
||
| 61 | } |
||
| 62 | |||
| 63 | |||
| 64 | foreach( $node->childNodes as $node ) |
||
| 65 | { |
||
| 66 | if( $node->nodeName !== 'catalogitem' |
||
| 67 | || ( $refattr = $node->attributes->getNamedItem( 'ref' ) ) === null |
||
| 68 | || !isset( $catItems[$refattr->nodeValue] ) |
||
| 69 | ) { |
||
| 70 | continue; |
||
| 71 | } |
||
| 72 | |||
| 73 | $list = []; |
||
| 74 | $catcode = $refattr->nodeValue; |
||
| 75 | $parentid = $catItems[$refattr->nodeValue]->getId(); |
||
| 76 | $typeattr = $node->attributes->getNamedItem( 'lists.type' ); |
||
| 77 | $type = ( $typeattr !== null ? $typeattr->nodeValue : 'default' ); |
||
| 78 | |||
| 79 | foreach( $node->attributes as $attrName => $attrNode ) { |
||
| 80 | $list['catalog.' . $attrName] = $attrNode->nodeValue; |
||
| 81 | } |
||
| 82 | |||
| 83 | $name = 'catalog.lists.config'; |
||
| 84 | $list[$name] = ( isset( $list[$name] ) ? (array) json_decode( $list[$name] ) : [] ); |
||
| 85 | $list['catalog.lists.type'] = $type; |
||
| 86 | |||
| 87 | |||
| 88 | if( isset( $map[$catcode][$type] ) ) { |
||
| 89 | $listItem = $map[$catcode][$type]; unset( $map[$catcode][$type] ); |
||
| 90 | } else { |
||
| 91 | $listItem = $listManager->createItem(); |
||
| 92 | } |
||
| 93 | |||
| 94 | $listItem = $listItem->fromArray( $list )->setDomain( 'product' ) |
||
| 95 | ->setRefId( $item->getId() )->setParentId( $parentid ); |
||
| 96 | $listManager->saveItem( $listItem, false ); |
||
| 97 | } |
||
| 98 | |||
| 99 | $listManager->deleteItems( array_keys( $listItems ) ); |
||
| 100 | |||
| 101 | return $item; |
||
| 102 | } |
||
| 139 |