Conditions | 4 |
Paths | 1 |
Total Lines | 61 |
Code Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Tests | 26 |
CRAP Score | 4.0176 |
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 |
||
22 | 2 | public static function build(): array |
|
23 | { |
||
24 | return [ |
||
25 | 1 | 'name' => 'confirmRegistration', |
|
26 | 1 | 'type' => Type::nonNull(Type::boolean()), |
|
27 | 1 | 'description' => 'Second step to register as a new user.', |
|
28 | 'args' => [ |
||
29 | 1 | 'token' => Type::nonNull(_types()->get('Token')), |
|
30 | 1 | 'input' => Type::nonNull(_types()->get('ConfirmRegistrationInput')), |
|
31 | ], |
||
32 | 'resolve' => function ($root, array $args, SessionInterface $session): bool { |
||
1 ignored issue
–
show
|
|||
33 | 2 | global $container; |
|
34 | /** @var Mailer $mailer */ |
||
35 | 2 | $mailer = $container->get(Mailer::class); |
|
36 | |||
37 | /** @var MessageQueuer $messageQueuer */ |
||
38 | 2 | $messageQueuer = $container->get(MessageQueuer::class); |
|
39 | |||
40 | /** @var UserRepository $repository */ |
||
41 | 2 | $repository = _em()->getRepository(User::class); |
|
42 | |||
43 | /** @var null|User $user */ |
||
44 | $user = $repository->getAclFilter()->runWithoutAcl(function () use ($repository, $args) { |
||
45 | 2 | return $repository->findOneByToken($args['token']); |
|
46 | 2 | }); |
|
47 | |||
48 | 2 | if (!$user) { |
|
49 | 1 | throw new Exception('Cannot confirm registration with an invalid token'); |
|
50 | } |
||
51 | |||
52 | 1 | if (!$user->isTokenValid()) { |
|
53 | throw new Exception('Le lien que vous avez suivi est périmé. Veuillez effectuer une nouvelle demande.'); |
||
54 | } |
||
55 | |||
56 | 1 | $input = $args['input']; |
|
57 | |||
58 | // Do it |
||
59 | 1 | Helper::hydrate($user, $input); |
|
60 | |||
61 | // Active the member |
||
62 | 1 | $user->initialize(); |
|
63 | |||
64 | // Login |
||
65 | 1 | User::setCurrent($user); |
|
66 | |||
67 | 1 | _em()->flush(); |
|
68 | |||
69 | // Give user automatic access via organization |
||
70 | /** @var OrganizationRepository $organizationRepository */ |
||
71 | 1 | $organizationRepository = _em()->getRepository(Organization::class); |
|
72 | 1 | $organizationRepository->applyOrganizationAccesses(); |
|
73 | |||
74 | /** @var UserRepository $repository */ |
||
75 | 1 | $repository = _em()->getRepository(User::class); |
|
76 | 1 | $admins = $repository->getAllAdministratorsToNotify(); |
|
77 | 1 | foreach ($admins as $admin) { |
|
78 | $message = $messageQueuer->queueConfirmedRegistration($admin, $user); |
||
79 | $mailer->sendMessageAsync($message); |
||
80 | } |
||
81 | |||
82 | 1 | return true; |
|
83 | 1 | }, |
|
87 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.