Conditions | 6 |
Paths | 12 |
Total Lines | 57 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
106 | public function process( \Aimeos\MShop\Product\Item\Iface $product, array $data ) : array |
||
107 | { |
||
108 | $context = $this->context(); |
||
109 | $manager = \Aimeos\MShop::create( $context, 'product' ); |
||
110 | $refManager = \Aimeos\MShop::create( $context, 'text' ); |
||
111 | |||
112 | $pos = 0; |
||
113 | $listMap = []; |
||
114 | $map = $this->getMappedChunk( $data, $this->getMapping() ); |
||
115 | $listItems = $product->getListItems( 'text', $this->listTypes, null, false ); |
||
116 | |||
117 | foreach( $listItems as $listItem ) |
||
118 | { |
||
119 | if( ( $refItem = $listItem->getRefItem() ) !== null ) { |
||
120 | $listMap[$refItem->getContent()][$refItem->getLanguageId()][$refItem->getType()][$listItem->getType()] = $listItem; |
||
121 | } |
||
122 | } |
||
123 | |||
124 | foreach( $map as $list ) |
||
125 | { |
||
126 | if( $this->checkEntry( $list ) === false ) { |
||
127 | continue; |
||
128 | } |
||
129 | |||
130 | $listtype = trim( $this->val( $list, 'product.lists.type', 'default' ) ); |
||
131 | $listConfig = $this->getListConfig( trim( $this->val( $list, 'product.lists.config', '' ) ) ); |
||
132 | |||
133 | $language = trim( $this->val( $list, 'text.languageid', '' ) ); |
||
134 | $content = trim( $this->val( $list, 'text.content', '' ) ); |
||
135 | $type = trim( $this->val( $list, 'text.type', 'name' ) ); |
||
136 | |||
137 | $this->addType( 'product/lists/type', 'text', $listtype ); |
||
138 | $this->addType( 'text/type', 'product', $type ); |
||
139 | |||
140 | if( isset( $listMap[$content][$language][$type][$listtype] ) ) |
||
141 | { |
||
142 | $listItem = $listMap[$content][$language][$type][$listtype]; |
||
143 | $refItem = $listItem->getRefItem(); |
||
144 | unset( $listItems[$listItem->getId()] ); |
||
145 | } |
||
146 | else |
||
147 | { |
||
148 | $listItem = $manager->createListItem()->setType( $listtype ); |
||
|
|||
149 | $refItem = $refManager->create()->setType( $type ); |
||
150 | } |
||
151 | |||
152 | $listItem = $listItem->setPosition( $pos++ )->fromArray( $list )->setConfig( $listConfig ); |
||
153 | |||
154 | $label = mb_strcut( strip_tags( trim( $this->val( $list, 'text.content', '' ) ) ), 0, 255 ); |
||
155 | $refItem = $refItem->setLabel( $label )->fromArray( $list ); |
||
156 | |||
157 | $product->addListItem( 'text', $listItem, $refItem ); |
||
158 | } |
||
159 | |||
160 | $product->deleteListItems( $listItems->toArray(), true ); |
||
161 | |||
162 | return $this->object()->process( $product, $data ); |
||
163 | } |
||
193 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.