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