Conditions | 1 |
Paths | 1 |
Total Lines | 177 |
Code Lines | 107 |
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 |
||
173 | public function contactInfoDataProvider() |
||
174 | { |
||
175 | return [ |
||
176 | 'items count' => [null, $this->getEntity()], |
||
177 | 'without contact info' => [null, $this->getEntity(['itemsCount' => 1])], |
||
178 | 'email' => [ |
||
179 | $this->getEntity(['itemsCount' => 1, 'email' => '[email protected]']), |
||
180 | $this->getEntity(['itemsCount' => 1, 'email' => '[email protected]']), |
||
181 | |||
182 | ], |
||
183 | 'do not change status' => [ |
||
184 | $this->getEntity( |
||
185 | ['itemsCount' => 1, 'email' => '[email protected]', 'status' => new CartStatus('custom')] |
||
186 | ), |
||
187 | $this->getEntity( |
||
188 | ['itemsCount' => 1, 'email' => '[email protected]', 'status' => new CartStatus('custom')] |
||
189 | ), |
||
190 | $this->getEntity( |
||
191 | ['itemsCount' => 1, 'email' => '[email protected]', 'status' => new CartStatus('custom')] |
||
192 | ) |
||
193 | ], |
||
194 | 'change status' => [ |
||
195 | 'expected' => $this->getEntity( |
||
196 | ['itemsCount' => 1, 'email' => '[email protected]', 'status' => new CartStatus('expired')] |
||
197 | ), |
||
198 | 'entity' => $this->getEntity( |
||
199 | ['itemsCount' => 1, 'email' => '[email protected]', 'status' => new CartStatus('expired')] |
||
200 | ), |
||
201 | 'databaseEntity' => $this->getEntity( |
||
202 | ['itemsCount' => 1, 'email' => '[email protected]', 'status' => new CartStatus('open')] |
||
203 | ) |
||
204 | ], |
||
205 | 'update customer email' => [ |
||
206 | 'expected' => $this->getEntity( |
||
207 | [ |
||
208 | 'itemsCount' => 1, |
||
209 | 'email' => '[email protected]', |
||
210 | 'customer' => $this->getCustomer('[email protected]'), |
||
211 | 'isGuest' => false |
||
212 | ] |
||
213 | ), |
||
214 | 'entity' => $this->getEntity( |
||
215 | [ |
||
216 | 'itemsCount' => 1, |
||
217 | 'email' => '[email protected]', |
||
218 | 'customer' => $this->getCustomer(), |
||
219 | 'isGuest' => false |
||
220 | ] |
||
221 | ), |
||
222 | 'databaseEntity' => $this->getEntity( |
||
223 | [ |
||
224 | 'itemsCount' => 1, |
||
225 | 'email' => '[email protected]', |
||
226 | 'customer' => $this->getCustomer('[email protected]'), |
||
227 | 'isGuest' => false |
||
228 | ] |
||
229 | ) |
||
230 | ], |
||
231 | 'update customer email for guest cart' => [ |
||
232 | 'expected' => $this->getEntity( |
||
233 | [ |
||
234 | 'itemsCount' => 1, |
||
235 | 'email' => '[email protected]', |
||
236 | 'customer' => $this->getCustomer('[email protected]'), |
||
237 | 'isGuest' => true |
||
238 | ] |
||
239 | ), |
||
240 | 'entity' => $this->getEntity( |
||
241 | [ |
||
242 | 'itemsCount' => 1, |
||
243 | 'email' => '[email protected]', |
||
244 | 'customer' => $this->getCustomer(), |
||
245 | 'isGuest' => true |
||
246 | ] |
||
247 | ), |
||
248 | 'databaseEntity' => $this->getEntity( |
||
249 | [ |
||
250 | 'itemsCount' => 1, |
||
251 | 'email' => '[email protected]', |
||
252 | 'customer' => $this->getCustomer('[email protected]'), |
||
253 | 'isGuest' => true |
||
254 | ] |
||
255 | ) |
||
256 | ], |
||
257 | 'add new cart item and remove old' => [ |
||
258 | 'expected' => $this->getEntity( |
||
259 | [ |
||
260 | 'itemsCount' => 1, |
||
261 | 'email' => '[email protected]', |
||
262 | 'cartItems' => new ArrayCollection([$this->getCartItem(1)]), |
||
263 | 'itemsQty' => 1, |
||
264 | ] |
||
265 | ), |
||
266 | 'entity' => $this->getEntity( |
||
267 | [ |
||
268 | 'itemsCount' => 1, |
||
269 | 'email' => '[email protected]', |
||
270 | 'cartItems' => new ArrayCollection([$this->getCartItem(1)]), |
||
271 | 'itemsQty' => 1, |
||
272 | ] |
||
273 | ), |
||
274 | 'databaseEntity' => $this->getEntity( |
||
275 | [ |
||
276 | 'itemsCount' => 1, |
||
277 | 'email' => '[email protected]', |
||
278 | 'cartItems' => new ArrayCollection([$this->getCartItem(2)]), |
||
279 | 'itemsQty' => 1, |
||
280 | ] |
||
281 | ) |
||
282 | ], |
||
283 | 'add new cart item and keep old one' => [ |
||
284 | 'expected' => $this->getEntity( |
||
285 | [ |
||
286 | 'itemsCount' => 1, |
||
287 | 'email' => '[email protected]', |
||
288 | 'cartItems' => new ArrayCollection([$this->getCartItem(1), $this->getCartItem(2)]), |
||
289 | 'itemsQty' => 2, |
||
290 | ] |
||
291 | ), |
||
292 | 'entity' => $this->getEntity( |
||
293 | [ |
||
294 | 'itemsCount' => 1, |
||
295 | 'email' => '[email protected]', |
||
296 | 'cartItems' => new ArrayCollection([$this->getCartItem(1), $this->getCartItem(2)]), |
||
297 | 'itemsQty' => 2, |
||
298 | ] |
||
299 | ), |
||
300 | 'databaseEntity' => $this->getEntity( |
||
301 | [ |
||
302 | 'itemsCount' => 1, |
||
303 | 'email' => '[email protected]', |
||
304 | 'cartItems' => new ArrayCollection([$this->getCartItem(2)]), |
||
305 | 'itemsQty' => 1, |
||
306 | ] |
||
307 | ) |
||
308 | ], |
||
309 | 'update existing address' => [ |
||
310 | 'expected' => $this->getEntity( |
||
311 | [ |
||
312 | 'itemsCount' => 1, |
||
313 | 'email' => '[email protected]', |
||
314 | 'shippingAddress' => $this->getAddress('US') |
||
315 | ] |
||
316 | ), |
||
317 | 'entity' => $this->getEntity( |
||
318 | [ |
||
319 | 'itemsCount' => 1, |
||
320 | 'email' => '[email protected]', |
||
321 | 'shippingAddress' => $this->getAddress('US') |
||
322 | ] |
||
323 | ), |
||
324 | 'databaseEntity' => $this->getEntity( |
||
325 | [ |
||
326 | 'itemsCount' => 1, |
||
327 | 'email' => '[email protected]', |
||
328 | 'shippingAddress' => $this->getAddress('US') |
||
329 | ] |
||
330 | ) |
||
331 | ], |
||
332 | 'drop without country' => [ |
||
333 | 'expected' => $this->getEntity( |
||
334 | [ |
||
335 | 'itemsCount' => 1, |
||
336 | 'email' => '[email protected]', |
||
337 | 'billingAddress' => null |
||
338 | ] |
||
339 | ), |
||
340 | 'entity' => $this->getEntity( |
||
341 | [ |
||
342 | 'itemsCount' => 1, |
||
343 | 'email' => '[email protected]', |
||
344 | 'billingAddress' => $this->getAddress() |
||
345 | ] |
||
346 | ) |
||
347 | ] |
||
348 | ]; |
||
349 | } |
||
350 | |||
497 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: