Conditions | 8 |
Paths | 10 |
Total Lines | 51 |
Code Lines | 30 |
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 |
||
35 | public function addItemAction(Request $request): RedirectResponse |
||
36 | { |
||
37 | $wishlistItemTransfer = $this->getWishlistItemTransferFromRequest($request); |
||
38 | if (!$wishlistItemTransfer) { |
||
39 | return $this->redirectResponseInternal(CustomerPageRouteProviderPlugin::ROUTE_NAME_LOGIN); |
||
40 | } |
||
41 | |||
42 | $wishlistAddItemForm = $this->getFactory()->getWishlistAddItemForm()->handleRequest($request); |
||
43 | |||
44 | if (!$wishlistAddItemForm->isSubmitted() || !$wishlistAddItemForm->isValid()) { |
||
45 | $this->addErrorMessage(static::MESSAGE_FORM_CSRF_VALIDATION_ERROR); |
||
46 | |||
47 | return $this->redirectResponseInternal(WishlistPageRouteProviderPlugin::ROUTE_NAME_WISHLIST_DETAILS, [ |
||
48 | 'wishlistName' => $wishlistItemTransfer->getWishlistName(), |
||
49 | ]); |
||
50 | } |
||
51 | |||
52 | $wishlistResponseTransfer = new WishlistResponseTransfer(); |
||
53 | if ($wishlistItemTransfer->getWishlistName() === static::DEFAULT_NAME) { |
||
54 | $wishlistResponseTransfer = $this->getFactory()->getWishlistClient()->validateAndCreateWishlist( |
||
55 | (new WishlistTransfer()) |
||
56 | ->setName(static::DEFAULT_NAME) |
||
57 | ->setFkCustomer($wishlistItemTransfer->getFkCustomer()), |
||
58 | ); |
||
59 | } |
||
60 | |||
61 | $wishlistItemTransfer = $this->getFactory() |
||
62 | ->getWishlistClient() |
||
63 | ->addItem($wishlistItemTransfer); |
||
64 | if (!$wishlistItemTransfer->getIdWishlistItem()) { |
||
65 | if ($wishlistResponseTransfer->getWishlist()) { |
||
66 | $this->getFactory()->getWishlistClient()->removeWishlistByName($wishlistResponseTransfer->getWishlist()); |
||
67 | } |
||
68 | |||
69 | $this->addErrorMessage('customer.account.wishlist.item.not_added'); |
||
70 | |||
71 | return $this->redirectResponseInternal(WishlistPageRouteProviderPlugin::ROUTE_NAME_WISHLIST_OVERVIEW, [ |
||
72 | 'wishlistName' => $wishlistItemTransfer->getWishlistName(), |
||
73 | ]); |
||
74 | } else { |
||
75 | $this->addSuccessMessage('cart.add.items.success'); |
||
76 | } |
||
77 | |||
78 | if ($request->headers->has(static::REQUEST_HEADER_REFERER)) { |
||
79 | return $this->redirectResponseExternal($request->headers->get(static::REQUEST_HEADER_REFERER)); |
||
80 | } |
||
81 | |||
82 | return $this->redirectResponseInternal( |
||
83 | WishlistPageRouteProviderPlugin::ROUTE_NAME_WISHLIST_DETAILS, |
||
84 | [ |
||
85 | 'wishlistName' => $wishlistItemTransfer->getWishlistName(), |
||
86 | ], |
||
90 |