Conditions | 11 |
Paths | 11 |
Total Lines | 64 |
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 |
||
28 | public function setSession(RequestEvent $event): void |
||
29 | { |
||
30 | if ($event->getRequestType() !== HttpKernelInterface::MAIN_REQUEST) { |
||
31 | return; |
||
32 | } |
||
33 | |||
34 | $request = $event->getRequest(); |
||
35 | |||
36 | /** @var Session $session */ |
||
37 | $session = $request->getSession(); |
||
38 | |||
39 | if (!$request->query->has(AffiliateReferralInterface::TOKEN_PARAM_NAME)) { |
||
40 | return; |
||
41 | } |
||
42 | |||
43 | $tokenValue = $request->query->get(AffiliateReferralInterface::TOKEN_PARAM_NAME); |
||
44 | if (null === $tokenValue) { |
||
45 | return; |
||
46 | } |
||
47 | |||
48 | if ($session->get(AffiliateReferralInterface::TOKEN_PARAM_NAME) === $tokenValue) { |
||
49 | return; |
||
50 | } |
||
51 | |||
52 | /** @var AffiliateReferralInterface|null $affiliateReferral */ |
||
53 | $affiliateReferral = $this->affiliateReferralRepository->findOneBy([ |
||
54 | 'tokenValue' => $tokenValue, |
||
55 | ]); |
||
56 | |||
57 | if (null === $affiliateReferral) { |
||
58 | $session->getFlashBag()->add('error', 'The referral link is invalid!'); |
||
59 | |||
60 | return; |
||
61 | } |
||
62 | |||
63 | if ($affiliateReferral->isExpired()) { |
||
64 | $session->getFlashBag()->add('info', 'The link you followed has expired!'); |
||
65 | |||
66 | return; |
||
67 | } |
||
68 | |||
69 | $token = $this->tokenStorage->getToken(); |
||
70 | if (!$token instanceof TokenInterface) { |
||
71 | return; |
||
72 | } |
||
73 | |||
74 | $affiliateReferralView = new AffiliateReferralView(); |
||
75 | $affiliateReferralView->setAffiliateReferral($affiliateReferral); |
||
76 | $affiliateReferralView->setIp($request->getClientIp()); |
||
77 | |||
78 | $shopUser = $token->getUser(); |
||
79 | |||
80 | if ($shopUser instanceof ShopUserInterface) { |
||
81 | $customer = $shopUser->getCustomer(); |
||
82 | if ($customer instanceof AffiliateInterface) { |
||
83 | if ($customer === $affiliateReferral->getAffiliate()) { |
||
84 | return; |
||
85 | } |
||
86 | } |
||
87 | } |
||
88 | |||
89 | $this->affiliateReferralViewRepository->add($affiliateReferralView); |
||
90 | |||
91 | $session->set(AffiliateReferralInterface::TOKEN_PARAM_NAME, $tokenValue); |
||
92 | } |
||
94 |