| Conditions | 6 |
| Paths | 17 |
| Total Lines | 54 |
| 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 |
||
| 116 | |||
| 117 | $item->addListItem( 'product', $listItem, $refItem ); |
||
| 118 | } |
||
| 119 | |||
| 120 | return $item; |
||
| 121 | } |
||
| 122 | |||
| 123 | |||
| 124 | protected function addSuppliers( \Aimeos\MShop\Common\Item\ListsRef\Iface $item, array $entries ) : \Aimeos\MShop\Common\Item\ListsRef\Iface |
||
| 125 | { |
||
| 126 | $manager = \Aimeos\MShop::create( $this->context(), 'supplier' ); |
||
| 127 | |||
| 128 | foreach( $entries as $data ) |
||
| 129 | { |
||
| 130 | $listItem = $manager->createListItem()->fromArray( $data ); |
||
| 131 | $refItem = $manager->find( $data['supplier.code'] ); |
||
| 132 | |||
| 133 | $item->addListItem( 'supplier', $listItem, $refItem ); |
||
| 134 | } |
||
| 135 | |||
| 136 | return $item; |
||
| 137 | } |
||
| 138 | |||
| 139 | |||
| 140 | /** |
||
| 141 | * Removes the referenced items from the given items. |
||
| 142 | * |
||
| 143 | * @param \Aimeos\Map $items List of items |
||
| 144 | * @param array $domains List of domain names |
||
| 145 | */ |
||
| 146 | public function removeRefItems( \Aimeos\Map $items, array $domains ) |
||
| 147 | { |
||
| 148 | $context = $this->context(); |
||
| 149 | |||
| 150 | foreach( $domains as $domain ) |
||
| 151 | { |
||
| 152 | $rmItems = map(); |
||
| 153 | |||
| 154 | foreach( $items as $item ) { |
||
| 155 | $rmItems->merge( $item->getRefItems( $domain, null, null, false )->filter( function( $item ) { |
||
| 156 | return strncmp( $item->getLabel(), 'Demo', 4 ) === 0; |
||
| 157 | } ) ); |
||
| 158 | } |
||
| 159 | |||
| 160 | \Aimeos\MShop::create( $context, $domain )->delete( $rmItems ); |
||
| 161 | } |
||
| 162 | } |
||
| 163 | } |
||
| 164 |