RunCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 6 1
B execute() 0 24 3
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