| Conditions | 7 |
| Paths | 15 |
| Total Lines | 55 |
| 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 | $context = $this->getContext(); |
||
| 83 | $manager = \Aimeos\MShop\Factory::createManager( $context, 'media' ); |
||
| 84 | $listManager = \Aimeos\MShop\Factory::createManager( $context, 'catalog/lists' ); |
||
| 85 | $separator = $context->getConfig()->get( 'controller/common/catalog/import/csv/separator', "\n" ); |
||
| 86 | |||
| 87 | $delete = $listMap = []; |
||
|
|
|||
| 88 | $map = $this->getMappedChunk( $data, $this->getMapping() ); |
||
| 89 | $listItems = $catalog->getListItems( 'media', $this->listTypes ); |
||
| 90 | |||
| 91 | foreach( $listItems as $listItem ) |
||
| 92 | { |
||
| 93 | if( ( $refItem = $listItem->getRefItem() ) !== null ) { |
||
| 94 | $listMap[ $refItem->getUrl() ][ $refItem->getType() ][ $listItem->getType() ] = $listItem; |
||
| 95 | } |
||
| 96 | } |
||
| 97 | |||
| 98 | foreach( $map as $pos => $list ) |
||
| 99 | { |
||
| 100 | if( $this->checkEntry( $list ) === false ) { |
||
| 101 | continue; |
||
| 102 | } |
||
| 103 | |||
| 104 | $urls = explode( $separator, trim( $list['media.url'] ) ); |
||
| 105 | $type = trim( $this->getValue( $list, 'media.type', 'default' ) ); |
||
| 106 | $typecode = trim( $this->getValue( $list, 'catalog.lists.type', 'default' ) ); |
||
| 107 | |||
| 108 | foreach( $urls as $url ) |
||
| 109 | { |
||
| 110 | if( isset( $listMap[$url][$type][$typecode] ) ) |
||
| 111 | { |
||
| 112 | $listItem = $listMap[$url][$type][$typecode]; |
||
| 113 | $refItem = $listItem->getRefItem(); |
||
| 114 | unset( $listItems[ $listItem->getId() ] ); |
||
| 115 | } |
||
| 116 | else |
||
| 117 | { |
||
| 118 | $listItem = $listManager->createItem( $typecode, 'media' ); |
||
| 119 | $refItem = $manager->createItem( $type, 'catalog' ); |
||
| 120 | } |
||
| 121 | |||
| 122 | $list['media.url'] = $url; |
||
| 123 | |||
| 124 | $list = $refItem->fromArray( $this->addItemDefaults( $list ) ); |
||
| 125 | $list = $listItem->fromArray( $this->addListItemDefaults( $list, $pos++ ) ); |
||
| 126 | |||
| 127 | $catalog->addListItem( 'media', $listItem, $refItem ); |
||
| 128 | } |
||
| 129 | } |
||
| 130 | |||
| 131 | $catalog->deleteListItems( $listItems, true ); |
||
| 132 | |||
| 133 | return $this->getObject()->process( $catalog, $data ); |
||
| 134 | } |
||
| 135 | |||
| 178 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.