Conditions | 8 |
Paths | 12 |
Total Lines | 54 |
Code Lines | 32 |
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 |
||
23 | protected function execute(InputInterface $input, OutputInterface $output) |
||
24 | { |
||
25 | $keepDeleted = $input->getOption('keep-deleted'); |
||
26 | $defaultDisabled = $input->getOption('default-disabled'); |
||
27 | $em = $this->getContainer()->get('doctrine.orm.entity_manager'); |
||
28 | |||
29 | // Enumerate the known jobs |
||
30 | $jobRepo = $em->getRepository('CronBundle:CronJob'); |
||
31 | $knownJobs = $jobRepo->getKnownJobs(); |
||
32 | $knownJobs = array_fill_keys($knownJobs, true); |
||
33 | |||
34 | // Enumerate all the jobs currently loaded |
||
35 | $reader = $this->getContainer()->get('annotation_reader'); |
||
36 | |||
37 | foreach ($this->getApplication()->all() as $command) { |
||
38 | // Check for an @CronJob annotation |
||
39 | $reflClass = new \ReflectionClass($command); |
||
40 | foreach ($reader->getClassAnnotations($reflClass) as $anno) { |
||
41 | if ($anno instanceof CronJobAnno) { |
||
42 | $job = $command->getName(); |
||
43 | if (array_key_exists($job, $knownJobs)) { |
||
44 | // Clear it from the known jobs so that we don't try to delete it |
||
45 | unset($knownJobs[$job]); |
||
46 | |||
47 | // Update the job if necessary |
||
48 | $currentJob = $jobRepo->findOneByCommand($job); |
||
49 | $currentJob->setDescription($command->getDescription()); |
||
50 | if ($currentJob->getInterval() != $anno->value) { |
||
51 | $newTime = new \DateTime(); |
||
52 | $newTime = $newTime->add(new \DateInterval($anno->value)); |
||
53 | |||
54 | $currentJob->setInterval($anno->value); |
||
55 | $currentJob->setNextRun($newTime); |
||
56 | $output->writeln("Updated interval for $job to {$anno->value}"); |
||
57 | } |
||
58 | } else { |
||
59 | $this->newJobFound($output, $command, $anno, $defaultDisabled); |
||
60 | } |
||
61 | } |
||
62 | } |
||
63 | } |
||
64 | |||
65 | // Clear any jobs that weren't found |
||
66 | if (!$keepDeleted) { |
||
67 | foreach (array_keys($knownJobs) as $deletedJob) { |
||
68 | $output->writeln("Deleting job: $deletedJob"); |
||
69 | $jobToDelete = $jobRepo->findOneByCommand($deletedJob); |
||
70 | $em->remove($jobToDelete); |
||
71 | } |
||
72 | } |
||
73 | |||
74 | $em->flush(); |
||
75 | $output->writeln('Finished scanning for cron jobs'); |
||
76 | } |
||
77 | |||
98 |
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: