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