Conditions | 7 |
Paths | 1 |
Total Lines | 74 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Tests | 34 |
CRAP Score | 7.0084 |
Changes | 4 | ||
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 |
||
25 | 2 | public static function build(): array |
|
26 | { |
||
27 | return [ |
||
28 | 1 | 'name' => 'confirmRegistration', |
|
29 | 1 | 'type' => Type::nonNull(Type::boolean()), |
|
30 | 1 | 'description' => 'First step to register as a new user.', |
|
31 | 'args' => [ |
||
32 | 1 | 'token' => Type::nonNull(_types()->get('Token')), |
|
33 | 1 | 'input' => Type::nonNull(_types()->get('ConfirmRegistrationInput')), |
|
34 | ], |
||
35 | 'resolve' => function ($root, array $args, SessionInterface $session): bool { |
||
1 ignored issue
–
show
|
|||
36 | |||
37 | /** @var UserRepository $repository */ |
||
38 | 2 | $repository = _em()->getRepository(User::class); |
|
39 | |||
40 | /** @var null|User $user */ |
||
41 | $user = $repository->getAclFilter()->runWithoutAcl(function () use ($repository, $args) { |
||
42 | 2 | return $repository->findOneByToken($args['token']); |
|
43 | 2 | }); |
|
44 | |||
45 | 2 | if (!$user) { |
|
46 | 1 | throw new Exception('Cannot confirm registration with an invalid token'); |
|
47 | } |
||
48 | |||
49 | 1 | if (!$user->isTokenValid()) { |
|
50 | throw new Exception('Le lien que vous avez suivi est périmé. Veuillez effectuer une nouvelle demande.'); |
||
51 | } |
||
52 | |||
53 | 1 | $input = $args['input']; |
|
54 | |||
55 | $repository->getAclFilter()->runWithoutAcl(function () use ($repository, $input): void { |
||
56 | 1 | if ($repository->findOneByLogin($input['login'])) { |
|
57 | throw new Exception('Ce nom d\'utilisateur est déjà attribué et ne peut être utilisé'); |
||
58 | } |
||
59 | 1 | }); |
|
60 | |||
61 | // Do it |
||
62 | 1 | Helper::hydrate($user, $input); |
|
63 | |||
64 | // Active the member |
||
65 | 1 | $user->initialize(); |
|
66 | |||
67 | // Create mandatory booking for him |
||
68 | 1 | User::setCurrent($user); |
|
69 | |||
70 | // Create account so the user can top-up money and start purchasing services |
||
71 | // but only if it's head of the family |
||
72 | 1 | if ($user->isFamilyOwner()) { |
|
73 | /** @var AccountRepository $accountRepository */ |
||
74 | 1 | $accountRepository = _em()->getRepository(Account::class); |
|
75 | 1 | $accountRepository->getOrCreate($user); |
|
76 | } |
||
77 | |||
78 | /** @var BookableRepository $bookableRepository */ |
||
79 | 1 | $bookableRepository = _em()->getRepository(Bookable::class); |
|
80 | 1 | $mandatoryBookables = $bookableRepository->findByBookingType(BookingTypeType::MANDATORY); |
|
81 | 1 | foreach ($mandatoryBookables as $bookable) { |
|
82 | 1 | $booking = new Booking(); |
|
83 | 1 | _em()->persist($booking); |
|
84 | |||
85 | 1 | $booking->setOwner($user); |
|
86 | 1 | $booking->setStatus(BookingStatusType::BOOKED); |
|
87 | 1 | $booking->setStartDate(new Chronos()); |
|
88 | 1 | $booking->setBookable($bookable); |
|
89 | |||
90 | // Non-periodic bookable must be terminated immediately |
||
91 | 1 | if ($bookable->getPeriodicPrice()->isZero()) { |
|
92 | 1 | $booking->terminate('Terminé automatiquement parce que paiement ponctuel uniquement'); |
|
93 | } |
||
94 | } |
||
95 | |||
96 | 1 | _em()->flush(); |
|
97 | |||
98 | 1 | return true; |
|
99 | 1 | }, |
|
103 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.