Conditions | 11 |
Paths | 63 |
Total Lines | 58 |
Code Lines | 44 |
Lines | 0 |
Ratio | 0 % |
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 |
||
21 | protected function execute(InputInterface $input, OutputInterface $output) |
||
22 | { |
||
23 | $em = $this->getContainer()->get('doctrine.orm.entity_manager'); |
||
24 | $jobRepo = $em->getRepository(CronJob::class); |
||
25 | |||
26 | $output->writeln('Cron job statuses:'); |
||
27 | |||
28 | $cronJobs = []; |
||
29 | if ($jobName = $input->getArgument('job')) { |
||
30 | try { |
||
31 | $cronJobs = [$jobRepo->findOneByCommand($jobName)]; |
||
32 | } catch (\Exception $e) { |
||
33 | $output->writeln("Couldn't find a job by the name of $jobName"); |
||
34 | |||
35 | return CronJobResult::FAILED; |
||
36 | } |
||
37 | } else { |
||
38 | $cronJobs = $em->getRepository('CronBundle:CronJob')->findAll(); |
||
39 | } |
||
40 | |||
41 | foreach ($cronJobs as $cronJob) { |
||
42 | $output->write(' - '.$cronJob->getCommand()); |
||
43 | if (!$cronJob->getEnabled()) { |
||
44 | $output->write(' (disabled)'); |
||
45 | } |
||
46 | $output->writeln(''); |
||
47 | $output->writeln(' Description: '.$cronJob->getDescription()); |
||
48 | if (!$cronJob->getEnabled()) { |
||
49 | $output->writeln(' Not scheduled'); |
||
50 | } else { |
||
51 | $output->write(' Scheduled for: '); |
||
52 | $now = new \DateTime(); |
||
53 | if ($cronJob->getNextRun() <= $now) { |
||
54 | $output->writeln('Next run'); |
||
55 | } else { |
||
56 | $output->writeln(strftime('%c', $cronJob->getNextRun()->getTimestamp())); |
||
57 | } |
||
58 | } |
||
59 | if ($cronJob->getMostRecentRun()) { |
||
60 | $status = 'Unknown'; |
||
61 | switch ($cronJob->getMostRecentRun()->getResult()) { |
||
62 | case CronJobResult::SUCCEEDED: |
||
63 | $status = 'Successful'; |
||
64 | break; |
||
65 | case CronJobResult::SKIPPED: |
||
66 | $status = 'Skipped'; |
||
67 | break; |
||
68 | case CronJobResult::FAILED: |
||
69 | $status = 'Failed'; |
||
70 | break; |
||
71 | } |
||
72 | $output->writeln(" Last run was: $status"); |
||
73 | } else { |
||
74 | $output->writeln(' This job has not yet been run'); |
||
75 | } |
||
76 | $output->writeln(''); |
||
77 | } |
||
78 | } |
||
79 | } |
||
80 |