RunCommand::execute()   B
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 24
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
cc 3
eloc 12
nc 3
nop 2
1
<?php
2
3
namespace Loevgaard\CronBundle\Command;
4
5
use Doctrine\ORM\EntityManager;
6
use Loevgaard\CronBundle\Entity\JobInterface;
7
use Loevgaard\CronBundle\Executor\Executor;
8
use Loevgaard\CronBundle\Resolver\Resolver;
9
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
class RunCommand extends ContainerAwareCommand
14
{
15
    protected function configure()
16
    {
17
        $this->setName('loevgaard:cron:run')
18
            ->setDescription('Runs scheduled cron jobs')
19
        ;
20
    }
21
22
    protected function execute(InputInterface $input, OutputInterface $output)
23
    {
24
        /** @var EntityManager $entityManager */
25
        $entityManager = $this->getContainer()->get('doctrine')->getManager();
26
27
        /** @var JobInterface[] $jobs */
28
        $jobs = $entityManager
29
            ->getRepository('LoevgaardCronBundle:Job')
30
            ->getEnabledJobs()
31
        ;
32
33
        if (count($jobs)) {
34
            $resolver = $this->getContainer()->get('loevgaard_cron.resolver');
35
            $executor = $this->getContainer()->get('loevgaard_cron.executor');
36
37
            $jobs = $resolver->resolve($jobs);
38
            $executor->run($jobs);
39
40
            $entityManager->flush();
41
42
            while ($executor->isRunning()) {
0 ignored issues
show
Unused Code introduced by
This while loop is empty and can be removed.

This check looks for while loops that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

Consider removing the loop.

Loading history...
43
            }
44
        }
45
    }
46
}
47