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