Conditions | 8 |
Paths | 12 |
Total Lines | 55 |
Code Lines | 35 |
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 |
||
46 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
47 | { |
||
48 | $io = new SymfonyStyle($input, $output); |
||
49 | $debug = $input->getOption('debug'); |
||
50 | $now = new DateTime('now', new DateTimeZone('UTC')); |
||
51 | $endDate = $now->format('Y-m-d'); |
||
52 | |||
53 | if ($debug) { |
||
54 | error_log('Debug mode activated'); |
||
55 | $io->note('Debug mode activated'); |
||
56 | } |
||
57 | |||
58 | $isActive = 'true' === $this->settingsManager->getSetting('crons.cron_remind_course_expiration_activate'); |
||
59 | |||
60 | if (!$isActive) { |
||
61 | if ($debug) { |
||
62 | error_log('Cron job for course expiration emails is not active.'); |
||
63 | $io->note('Cron job for course expiration emails is not active.'); |
||
64 | } |
||
65 | return Command::SUCCESS; |
||
66 | } |
||
67 | |||
68 | $sessionRepo = $this->entityManager->getRepository(Session::class); |
||
69 | $sessions = $sessionRepo->createQueryBuilder('s') |
||
70 | ->where('s.accessEndDate LIKE :date') |
||
71 | ->setParameter('date', "$endDate%") |
||
72 | ->getQuery() |
||
73 | ->getResult(); |
||
74 | |||
75 | if (empty($sessions)) { |
||
76 | $io->success("No sessions finishing today $endDate"); |
||
77 | return Command::SUCCESS; |
||
78 | } |
||
79 | |||
80 | $administrator = [ |
||
81 | 'complete_name' => $this->getAdministratorName(), |
||
82 | 'email' => $this->settingsManager->getSetting('admin.administrator_email'), |
||
83 | ]; |
||
84 | |||
85 | foreach ($sessions as $session) { |
||
86 | $sessionUsers = $session->getUsers(); |
||
87 | |||
88 | if (empty($sessionUsers)) { |
||
89 | $io->warning('No users to send mail for session: ' . $session->getTitle()); |
||
90 | continue; |
||
91 | } |
||
92 | |||
93 | foreach ($sessionUsers as $sessionUser) { |
||
94 | $user = $sessionUser->getUser(); |
||
95 | $this->sendEmailToUser($user, $session, $administrator, $io, $debug); |
||
96 | } |
||
97 | } |
||
98 | |||
99 | $io->success('Emails sent successfully for sessions expiring today.'); |
||
100 | return Command::SUCCESS; |
||
101 | } |
||
143 |