| Conditions | 5 |
| Paths | 1 |
| Total Lines | 53 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 6 |
| CRAP Score | 17.1256 |
| 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 |
||
| 22 | 1 | public static function build(): array |
|
| 23 | { |
||
| 24 | return [ |
||
| 25 | 1 | 'name' => 'confirmRegistration', |
|
| 26 | 1 | 'type' => Type::nonNull(Type::boolean()), |
|
| 27 | 1 | 'description' => 'First step to register as a new user.', |
|
| 28 | 'args' => [ |
||
| 29 | 1 | 'token' => Type::nonNull(_types()->get('Token')), |
|
|
1 ignored issue
–
show
|
|||
| 30 | 1 | 'input' => Type::nonNull(_types()->get('ConfirmRegistrationInput')), |
|
| 31 | ], |
||
| 32 | 'resolve' => function ($root, array $args, SessionInterface $session): bool { |
||
|
1 ignored issue
–
show
|
|||
| 33 | |||
| 34 | /** @var UserRepository $repository */ |
||
| 35 | $repository = _em()->getRepository(User::class); |
||
| 36 | |||
| 37 | /** @var User $user */ |
||
| 38 | $repository->getAclFilter()->setEnabled(false); |
||
| 39 | $user = $repository->findOneByToken($args['token']); |
||
|
1 ignored issue
–
show
|
|||
| 40 | $repository->getAclFilter()->setEnabled(true); |
||
| 41 | |||
| 42 | if (!$user || !$user->isTokenValid()) { |
||
| 43 | throw new Exception('Cannot confirm registration with an invalid token'); |
||
| 44 | } |
||
| 45 | |||
| 46 | // Do it |
||
| 47 | $input = $args['input']; |
||
| 48 | Helper::hydrate($user, $input); |
||
| 49 | |||
| 50 | // Active the member |
||
| 51 | $user->initialize(); |
||
| 52 | |||
| 53 | // Create mandatory booking for him |
||
| 54 | User::setCurrent($user); |
||
| 55 | |||
| 56 | $mandatoryBookables = _em()->getRepository(Bookable::class)->findByBookingType(BookingTypeType::MANDATORY); |
||
|
1 ignored issue
–
show
|
|||
| 57 | foreach ($mandatoryBookables as $bookable) { |
||
| 58 | $booking = new Booking(); |
||
| 59 | _em()->persist($booking); |
||
| 60 | |||
| 61 | $booking->setOwner($user); |
||
| 62 | $booking->setStatus(BookingStatusType::BOOKED); |
||
| 63 | $booking->setStartDate(new Chronos()); |
||
| 64 | $booking->setBookable($bookable); |
||
| 65 | |||
| 66 | // Non-periodic bookable must be terminated immediately |
||
| 67 | if (bccomp($bookable->getPeriodicPrice(), '0.00') === 0) { |
||
| 68 | $booking->terminate('Terminé automatiquement parce que paiement ponctuel uniquement'); |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | _em()->flush(); |
||
| 73 | |||
| 74 | return true; |
||
| 75 | 1 | }, |
|
| 79 |