| Conditions | 10 |
| Paths | 673 |
| Total Lines | 74 |
| Code Lines | 43 |
| 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 |
||
| 80 | public function process( \Aimeos\MShop\Catalog\Item\Iface $catalog, array $data ) |
||
| 81 | { |
||
| 82 | $listManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'catalog/lists' ); |
||
| 83 | $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'text' ); |
||
| 84 | $manager->begin(); |
||
| 85 | |||
| 86 | try |
||
| 87 | { |
||
| 88 | $delete = $listMap = []; |
||
| 89 | $map = $this->getMappedChunk( $data, $this->getMapping() ); |
||
| 90 | $listItems = $catalog->getListItems( 'text', $this->listTypes ); |
||
| 91 | |||
| 92 | foreach( $listItems as $listItem ) |
||
| 93 | { |
||
| 94 | if( ( $refItem = $listItem->getRefItem() ) !== null ) { |
||
| 95 | $listMap[ $refItem->getContent() ][ $refItem->getType() ][ $listItem->getType() ] = $listItem; |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | foreach( $map as $pos => $list ) |
||
| 100 | { |
||
| 101 | if( $this->checkEntry( $list ) === false ) { |
||
| 102 | continue; |
||
| 103 | } |
||
| 104 | |||
| 105 | $type = ( isset( $list['text.type'] ) ? $list['text.type'] : 'name' ); |
||
| 106 | $typecode = ( isset( $list['catalog.lists.type'] ) ? $list['catalog.lists.type'] : 'default' ); |
||
| 107 | |||
| 108 | if( isset( $listMap[ $list['text.content'] ][$type][$typecode] ) ) |
||
| 109 | { |
||
| 110 | $listItem = $listMap[ $list['text.content'] ][$type][$typecode]; |
||
| 111 | $refItem = $listItem->getRefItem(); |
||
| 112 | unset( $listItems[ $listItem->getId() ] ); |
||
| 113 | } |
||
| 114 | else |
||
| 115 | { |
||
| 116 | $listItem = $listManager->createItem(); |
||
| 117 | $refItem = $manager->createItem(); |
||
| 118 | } |
||
| 119 | |||
| 120 | $list['text.typeid'] = $this->getTypeId( 'text/type', 'catalog', $type ); |
||
| 121 | $list['text.domain'] = 'catalog'; |
||
| 122 | |||
| 123 | $refItem->fromArray( $this->addItemDefaults( $list ) ); |
||
| 124 | $refItem = $manager->saveItem( $refItem ); |
||
| 125 | |||
| 126 | $list['catalog.lists.typeid'] = $this->getTypeId( 'catalog/lists/type', 'text', $typecode ); |
||
| 127 | $list['catalog.lists.parentid'] = $catalog->getId(); |
||
| 128 | $list['catalog.lists.refid'] = $refItem->getId(); |
||
| 129 | $list['catalog.lists.domain'] = 'text'; |
||
| 130 | |||
| 131 | $listItem->fromArray( $this->addListItemDefaults( $list, $pos ) ); |
||
| 132 | $listManager->saveItem( $listItem, false ); |
||
| 133 | } |
||
| 134 | |||
| 135 | foreach( $listItems as $listItem ) { |
||
| 136 | $delete[] = $listItem->getRefId(); |
||
| 137 | } |
||
| 138 | |||
| 139 | $manager->deleteItems( $delete ); |
||
| 140 | $listManager->deleteItems( array_keys( $listItems ) ); |
||
| 141 | |||
| 142 | $data = $this->getObject()->process( $catalog, $data ); |
||
| 143 | |||
| 144 | $manager->commit(); |
||
| 145 | } |
||
| 146 | catch( \Exception $e ) |
||
| 147 | { |
||
| 148 | $manager->rollback(); |
||
| 149 | throw $e; |
||
| 150 | } |
||
| 151 | |||
| 152 | return $data; |
||
| 153 | } |
||
| 154 | |||
| 197 |