Conditions | 7 |
Paths | 47 |
Total Lines | 53 |
Code Lines | 29 |
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 |
||
43 | public function process( \Aimeos\MShop\Product\Item\Iface $product, array $data ) |
||
44 | { |
||
45 | $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product/property' ); |
||
46 | $manager->begin(); |
||
47 | |||
48 | try |
||
49 | { |
||
50 | $propPap = array(); |
||
51 | $map = $this->getMappedChunk( $data ); |
||
52 | $items = $this->getPropertyItems( $product->getId() ); |
||
53 | |||
54 | foreach( $items as $item ) { |
||
55 | $propMap[ $item->getValue() ][ $item->getType() ] = $item; |
||
56 | } |
||
57 | |||
58 | foreach( $map as $list ) |
||
59 | { |
||
60 | if( $list['product.property.type'] == '' || $list['product.property.value'] == '' ) { |
||
61 | continue; |
||
62 | } |
||
63 | |||
64 | $typecode = $list['product.property.type']; |
||
65 | $list['product.property.typeid'] = $this->getTypeId( 'product/property/type', 'product', $typecode ); |
||
66 | $list['product.property.parentid'] = $product->getId(); |
||
67 | |||
68 | if( isset( $propMap[ $list['product.property.value'] ][$typecode] ) ) |
||
69 | { |
||
70 | $item = $propMap[ $list['product.property.value'] ][$typecode]; |
||
71 | unset( $items[ $item->getId() ] ); |
||
72 | } |
||
73 | else |
||
74 | { |
||
75 | $item = $manager->createItem(); |
||
76 | } |
||
77 | |||
78 | $item->fromArray( $list ); |
||
79 | $manager->saveItem( $item ); |
||
80 | } |
||
81 | |||
82 | $manager->deleteItems( array_keys( $items ) ); |
||
83 | |||
84 | $remaining = $this->getObject()->process( $product, $data ); |
||
85 | |||
86 | $manager->commit(); |
||
87 | } |
||
88 | catch( \Exception $e ) |
||
89 | { |
||
90 | $manager->rollback(); |
||
91 | throw $e; |
||
92 | } |
||
93 | |||
94 | return $remaining; |
||
95 | } |
||
96 | |||
114 |