Conditions | 8 |
Paths | 12 |
Total Lines | 54 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
24 | protected function execute(InputInterface $input, OutputInterface $output) |
||
25 | { |
||
26 | $keepDeleted = $input->getOption('keep-deleted'); |
||
27 | $defaultDisabled = $input->getOption('default-disabled'); |
||
28 | $em = $this->getContainer()->get('doctrine.orm.entity_manager'); |
||
29 | |||
30 | // Enumerate the known jobs |
||
31 | $jobRepo = $em->getRepository('CronBundle:CronJob'); |
||
32 | $knownJobs = $jobRepo->getKnownJobs(); |
||
33 | $knownJobs = array_fill_keys($knownJobs, true); |
||
34 | |||
35 | // Enumerate all the jobs currently loaded |
||
36 | $reader = $this->getContainer()->get('annotation_reader'); |
||
37 | |||
38 | foreach ($this->getApplication()->all() as $command) { |
||
39 | // Check for an @CronJob annotation |
||
40 | $reflClass = new \ReflectionClass($command); |
||
41 | foreach ($reader->getClassAnnotations($reflClass) as $anno) { |
||
42 | if ($anno instanceof CronJobAnno) { |
||
43 | $job = $command->getName(); |
||
44 | if (array_key_exists($job, $knownJobs)) { |
||
45 | // Clear it from the known jobs so that we don't try to delete it |
||
46 | unset($knownJobs[$job]); |
||
47 | |||
48 | // Update the job if necessary |
||
49 | $currentJob = $jobRepo->findOneByCommand($job); |
||
50 | $currentJob->setDescription($command->getDescription()); |
||
51 | if ($currentJob->getInterval() != $anno->value) { |
||
52 | $newTime = new \DateTime(); |
||
53 | $newTime = $newTime->add(new \DateInterval($anno->value)); |
||
54 | |||
55 | $currentJob->setInterval($anno->value); |
||
56 | $currentJob->setNextRun($newTime); |
||
57 | $output->writeln("Updated interval for $job to {$anno->value}"); |
||
58 | } |
||
59 | } else { |
||
60 | $this->newJobFound($em, $output, $command, $anno, $defaultDisabled); |
||
61 | } |
||
62 | } |
||
63 | } |
||
64 | } |
||
65 | |||
66 | // Clear any jobs that weren't found |
||
67 | if (!$keepDeleted) { |
||
68 | foreach (array_keys($knownJobs) as $deletedJob) { |
||
69 | $output->writeln("Deleting job: $deletedJob"); |
||
70 | $jobToDelete = $jobRepo->findOneByCommand($deletedJob); |
||
71 | $em->remove($jobToDelete); |
||
72 | } |
||
73 | } |
||
74 | |||
75 | $em->flush(); |
||
76 | $output->writeln('Finished scanning for cron jobs'); |
||
77 | } |
||
78 | |||
92 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: