Conditions | 10 |
Paths | 14 |
Total Lines | 46 |
Code Lines | 30 |
Lines | 14 |
Ratio | 30.43 % |
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 |
||
26 | protected function execute(InputInterface $input, OutputInterface $output) |
||
27 | { |
||
28 | $em = $this->getContainer()->get('doctrine')->getManager(); |
||
29 | $userRepo = $this->getContainer()->get('doctrine')->getRepository(Club::class); |
||
30 | $clubUserRepo = $this->getContainer()->get('doctrine')->getRepository(ClubUser::class); |
||
31 | $assoPromo = $this->getContainer()->getParameter('upont')['promos']['assos']; |
||
32 | $clubSlugs = $input->getArgument('clubs'); |
||
33 | |||
34 | if ($input->getOption('all')) { |
||
35 | $clubsToUpdate = $userRepo->findAll(); |
||
36 | } |
||
37 | else { |
||
38 | $clubsToUpdate = array_map([$userRepo, 'findOneBySlug'], $clubSlugs); |
||
39 | } |
||
40 | |||
41 | $clubNumber = -1; |
||
42 | foreach ($clubsToUpdate as $clubToUpdate) { |
||
43 | $clubNumber++; |
||
44 | if (count($clubToUpdate) == 0) { |
||
45 | $output->writeln('<error>The slug "'.$clubSlugs[$clubNumber].'" doesn\'t match with any club</error>'); |
||
46 | continue; |
||
47 | } |
||
48 | $countUsers = $clubUserRepo->getCountUsersInClubWithPromo($clubToUpdate, $assoPromo); |
||
49 | |||
50 | if ($countUsers == 0 && $clubToUpdate->getActive()) { |
||
51 | View Code Duplication | if ($input->getOption('preview')) { |
|
52 | $output->writeln('<comment>'.$clubToUpdate->getFullName().' to be disabled'.'</comment>'); |
||
53 | } |
||
54 | else { |
||
55 | $clubToUpdate->setActive(false); |
||
56 | $output->writeln('<comment>'.$clubToUpdate->getFullName().' disabled'.'</comment>'); |
||
57 | } |
||
58 | } |
||
59 | else if ($countUsers > 0 && !$clubToUpdate->getActive()) { |
||
60 | View Code Duplication | if ($input->getOption('preview')) { |
|
61 | $output->writeln('<info>'.$clubToUpdate->getFullName().' to be enabled'.'</info>'); |
||
62 | } |
||
63 | else { |
||
64 | $clubToUpdate->setActive(true); |
||
65 | $output->writeln('<info>'.$clubToUpdate->getFullName().' enabled'.'</info>'); |
||
66 | } |
||
67 | } |
||
68 | } |
||
69 | |||
70 | $em->flush(); |
||
71 | } |
||
72 | } |
||
73 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.