Conditions | 11 |
Paths | 1297 |
Total Lines | 75 |
Code Lines | 44 |
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\Product\Item\Iface $product, array $data ) |
||
81 | { |
||
82 | $listManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product/lists' ); |
||
83 | $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'price' ); |
||
84 | $manager->begin(); |
||
85 | |||
86 | try |
||
87 | { |
||
88 | $delete = $listMap = array(); |
||
89 | $map = $this->getMappedChunk( $data ); |
||
90 | $listItems = $product->getListItems( 'price', $this->listTypes ); |
||
91 | |||
92 | foreach( $listItems as $listItem ) |
||
93 | { |
||
94 | if( ( $refItem = $listItem->getRefItem() ) !== null ) { |
||
95 | $listMap[ $refItem->getValue() ][ $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 | $value = ( isset( $list['price.value'] ) ? $list['price.value'] : '0.00' ); |
||
106 | $type = ( isset( $list['price.type'] ) ? $list['price.type'] : 'default' ); |
||
107 | $typecode = ( isset( $list['product.lists.type'] ) ? $list['product.lists.type'] : 'default' ); |
||
108 | |||
109 | if( isset( $listMap[$value][$type][$typecode] ) ) |
||
110 | { |
||
111 | $listItem = $listMap[$value][$type][$typecode]; |
||
112 | $refItem = $listItem->getRefItem(); |
||
113 | unset( $listItems[ $listItem->getId() ] ); |
||
114 | } |
||
115 | else |
||
116 | { |
||
117 | $listItem = $listManager->createItem(); |
||
118 | $refItem = $manager->createItem(); |
||
119 | } |
||
120 | |||
121 | $list['price.typeid'] = $this->getTypeId( 'price/type', 'product', $type ); |
||
122 | $list['price.domain'] = 'product'; |
||
123 | |||
124 | $refItem->fromArray( $this->addItemDefaults( $list ) ); |
||
125 | $manager->saveItem( $refItem ); |
||
126 | |||
127 | $list['product.lists.typeid'] = $this->getTypeId( 'product/lists/type', 'price', $typecode ); |
||
128 | $list['product.lists.parentid'] = $product->getId(); |
||
129 | $list['product.lists.refid'] = $refItem->getId(); |
||
130 | $list['product.lists.domain'] = 'price'; |
||
131 | |||
132 | $listItem->fromArray( $this->addListItemDefaults( $list, $pos ) ); |
||
133 | $listManager->saveItem( $listItem ); |
||
134 | } |
||
135 | |||
136 | foreach( $listItems as $listItem ) { |
||
137 | $delete[] = $listItem->getRefId(); |
||
138 | } |
||
139 | |||
140 | $manager->deleteItems( $delete ); |
||
141 | $listManager->deleteItems( array_keys( $listItems ) ); |
||
142 | |||
143 | $remaining = $this->getObject()->process( $product, $data ); |
||
144 | |||
145 | $manager->commit(); |
||
146 | } |
||
147 | catch( \Exception $e ) |
||
148 | { |
||
149 | $manager->rollback(); |
||
150 | throw $e; |
||
151 | } |
||
152 | |||
153 | return $remaining; |
||
154 | } |
||
155 | |||
198 |