| Conditions | 11 |
| Paths | 34 |
| Total Lines | 70 |
| Code Lines | 41 |
| 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 |
||
| 52 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 53 | { |
||
| 54 | $debug = $input->getOption('debug'); |
||
| 55 | |||
| 56 | $expiredViews = $this->lpRepository->findExpiredViews(0); |
||
| 57 | |||
| 58 | if ($debug) { |
||
| 59 | $output->writeln(sprintf('Found %d expired views.', count($expiredViews))); |
||
| 60 | } |
||
| 61 | |||
| 62 | foreach ($expiredViews as $view) { |
||
| 63 | $user = $view->getUser(); |
||
| 64 | $session = $view->getSession(); |
||
| 65 | $lp = $view->getLp(); |
||
| 66 | |||
| 67 | if ($debug) { |
||
| 68 | $output->writeln(sprintf( |
||
| 69 | 'User %d completed course %d associated with session %d, and its validity has expired.', |
||
| 70 | $user->getId(), |
||
| 71 | $lp->getIid(), |
||
| 72 | $session->getId() |
||
| 73 | )); |
||
| 74 | } |
||
| 75 | |||
| 76 | // Check if the session is marked as the last repetition |
||
| 77 | if ($session->getLastRepetition()) { |
||
| 78 | if ($debug) { |
||
| 79 | $output->writeln('The session is marked as the last repetition. Skipping...'); |
||
| 80 | } |
||
| 81 | continue; |
||
| 82 | } |
||
| 83 | |||
| 84 | // Find a valid child session |
||
| 85 | $validChildSession = $this->sessionRepository->findValidChildSession($session); |
||
| 86 | |||
| 87 | if ($validChildSession) { |
||
| 88 | $this->enrollUserInSession($user, $validChildSession); |
||
| 89 | if ($debug) { |
||
| 90 | $output->writeln(sprintf( |
||
| 91 | 'User %d re-enrolled into the valid child session %d.', |
||
| 92 | $user->getId(), |
||
| 93 | $validChildSession->getId() |
||
| 94 | )); |
||
| 95 | } |
||
| 96 | continue; |
||
| 97 | } |
||
| 98 | |||
| 99 | // If no valid child session exists, check the parent session |
||
| 100 | $validParentSession = $this->sessionRepository->findValidParentSession($session); |
||
| 101 | |||
| 102 | if ($validParentSession) { |
||
| 103 | $this->enrollUserInSession($user, $validParentSession); |
||
| 104 | if ($debug) { |
||
| 105 | $output->writeln(sprintf( |
||
| 106 | 'User %d re-enrolled into the valid parent session %d.', |
||
| 107 | $user->getId(), |
||
| 108 | $validParentSession->getId() |
||
| 109 | )); |
||
| 110 | } |
||
| 111 | } else { |
||
| 112 | if ($debug) { |
||
| 113 | $output->writeln(sprintf( |
||
| 114 | 'No valid child or parent session found for user %d.', |
||
| 115 | $user->getId() |
||
| 116 | )); |
||
| 117 | } |
||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 121 | return Command::SUCCESS; |
||
| 122 | } |
||
| 168 |
This check looks for private methods that have been defined, but are not used inside the class.