Conditions | 8 |
Paths | 56 |
Total Lines | 54 |
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 |
||
111 | } ); |
||
112 | |||
113 | $customer->deleteListItems( $remove ); |
||
114 | } |
||
115 | |||
116 | return $customers; |
||
117 | } |
||
118 | |||
119 | |||
120 | /** |
||
121 | * Returns a filtered list of products for which a notification should be sent |
||
122 | * |
||
123 | * @param \Aimeos\Map $listItems List of customer list items |
||
124 | * @return array Associative list of list IDs as key and product items values |
||
125 | */ |
||
126 | protected function products( \Aimeos\Map $listItems ) : array |
||
127 | { |
||
128 | $priceManager = \Aimeos\MShop::create( $this->context(), 'price' ); |
||
129 | $result = []; |
||
130 | |||
131 | foreach( $listItems as $id => $listItem ) |
||
132 | { |
||
133 | try |
||
134 | { |
||
135 | if( $product = $listItem->getRefItem() ) |
||
136 | { |
||
137 | $config = $listItem->getConfig(); |
||
138 | $prices = $product->getRefItems( 'price', 'default', 'default' ); |
||
139 | $price = $priceManager->getLowestPrice( $prices, 1, $config['currency'] ?? null ); |
||
140 | |||
141 | if( $config['stock'] ?? null || $config['price'] ?? null |
||
142 | && $product->inStock() && ( $config['pricevalue'] ?? 0 ) > $price->getValue() |
||
143 | ) { |
||
144 | $result[$id] = $product->set( 'price', $price ); |
||
145 | } |
||
146 | } |
||
147 | } |
||
148 | catch( \Exception $e ) { ; } // no price available |
||
149 | } |
||
150 | |||
151 | return $result; |
||
152 | } |
||
153 | |||
154 | |||
155 | /** |
||
156 | * Sends the notification e-mail for the given customer address and products |
||
157 | * |
||
158 | * @param \Aimeos\MShop\Customer\Item\Iface $item Customer item object |
||
159 | * @param array $products List of products a notification should be sent for |
||
160 | */ |
||
161 | protected function send( \Aimeos\MShop\Customer\Item\Iface $item, array $products ) |
||
162 | { |
||
163 | $context = $this->context(); |
||
164 | $config = $context->config(); |
||
165 | $address = $item->getPaymentAddress(); |
||
183 |