| Conditions | 12 |
| Paths | 57 |
| Total Lines | 72 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 112 | public function process( \Aimeos\MShop\Product\Item\Iface $product, array $data ) |
||
| 113 | { |
||
| 114 | $context = $this->getContext(); |
||
| 115 | $manager = \Aimeos\MShop::create( $context, 'media' ); |
||
| 116 | $listManager = \Aimeos\MShop::create( $context, 'product/lists' ); |
||
| 117 | $separator = $context->getConfig()->get( 'controller/common/product/import/csv/separator', "\n" ); |
||
| 118 | |||
| 119 | $listMap = []; |
||
| 120 | $map = $this->getMappedChunk( $data, $this->getMapping() ); |
||
| 121 | $listItems = $product->getListItems( 'media', $this->listTypes ); |
||
| 122 | $cntl = \Aimeos\Controller\Common\Media\Factory::create( $context ); |
||
| 123 | |||
| 124 | foreach( $listItems as $listItem ) |
||
| 125 | { |
||
| 126 | if( ( $refItem = $listItem->getRefItem() ) !== null ) { |
||
| 127 | $listMap[$refItem->getUrl()][$refItem->getType()][$listItem->getType()] = $listItem; |
||
| 128 | } |
||
| 129 | } |
||
| 130 | |||
| 131 | foreach( $map as $pos => $list ) |
||
| 132 | { |
||
| 133 | if( $this->checkEntry( $list ) === false ) { |
||
| 134 | continue; |
||
| 135 | } |
||
| 136 | |||
| 137 | $type = $this->getValue( $list, 'media.type', 'default' ); |
||
| 138 | $listtype = $this->getValue( $list, 'product.lists.type', 'default' ); |
||
| 139 | $urls = explode( $separator, $this->getValue( $list, 'media.url', '' ) ); |
||
| 140 | $preview = explode( $separator, $this->getValue( $list, 'media.preview', '' ) ); |
||
| 141 | $previews = explode( $separator, $this->getValue( $list, 'media.previews', '' ) ); |
||
| 142 | |||
| 143 | unset( $list['media.preview'], $list['media.previews'], $list['media.url'] ); |
||
| 144 | |||
| 145 | foreach( $urls as $idx => $url ) |
||
| 146 | { |
||
| 147 | $url = trim( $url ); |
||
| 148 | |||
| 149 | if( isset( $listMap[$url][$type][$listtype] ) ) |
||
| 150 | { |
||
| 151 | $listItem = $listMap[$url][$type][$listtype]; |
||
| 152 | $refItem = $listItem->getRefItem(); |
||
| 153 | unset( $listItems[$listItem->getId()] ); |
||
| 154 | } |
||
| 155 | else |
||
| 156 | { |
||
| 157 | $listItem = $listManager->createItem()->setType( $listtype ); |
||
| 158 | $refItem = $manager->createItem()->setType( $type ); |
||
| 159 | } |
||
| 160 | |||
| 161 | $ext = pathinfo( $url, PATHINFO_EXTENSION ); |
||
| 162 | if( isset( $this->mimes[$ext] ) ) { |
||
| 163 | $refItem->setMimeType( $this->mimes[$ext] ); |
||
| 164 | } |
||
| 165 | |||
| 166 | $listItem = $listItem->setPosition( $pos++ )->fromArray( $list ); |
||
| 167 | $refItem = $refItem->setLabel( $url )->fromArray( $list )->setUrl( $url ); |
||
| 168 | |||
| 169 | if( isset( $previews[$idx] ) && ( $map = json_decode( $previews[$idx], true ) ) !== null ) { |
||
| 170 | $refItem->setPreviews( $map ); |
||
| 171 | } elseif( isset( $preview[$idx] ) ) { |
||
| 172 | $refItem->setPreview( $preview[$idx] ); |
||
| 173 | } elseif( $refItem->isModified() ) { |
||
| 174 | $refItem = $cntl->scale( $refItem ); |
||
| 175 | } |
||
| 176 | |||
| 177 | $product->addListItem( 'media', $listItem, $refItem ); |
||
| 178 | } |
||
| 179 | } |
||
| 180 | |||
| 181 | $product->deleteListItems( $listItems, true ); |
||
| 182 | |||
| 183 | return $this->getObject()->process( $product, $data ); |
||
| 184 | } |
||
| 214 |