MatchdayCommand::executeOnce()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 8
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
crap 2
1
<?php
2
3
namespace OSS\CoreBundle\Command;
4
5
use OSS\CoreBundle\CoreEvents;
6
use OSS\CoreBundle\Entity\GameDate;
7
use OSS\CoreBundle\Event\GameDateEvent;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class MatchdayCommand extends BaseCommand
13
{
14
    protected function configure()
15
    {
16
        $this->setName('oss:matchday');
17
        $this->setDescription('Evaluates the current matchday');
18
        $this->addArgument('count', InputArgument::OPTIONAL, 'How many times shall the matchday command be executed?', 1);
19
    }
20
21
    protected function execute(InputInterface $input, OutputInterface $output)
22
    {
23
        for ($i = 1; $i <= $input->getArgument('count'); $i++) {
24
            $this->executeOnce();
25
        }
26
    }
27
28
    private function executeOnce()
29
    {
30
        /** @var GameDate $gameDate */
31
        $gameDate = $this->getGameDateRepository()->findOneBy(array());
32
33
        $this->getContainer()->get('event_dispatcher')->dispatch(CoreEvents::PRE_WEEK_CHANGE, new GameDateEvent($gameDate));
34
        $gameDate->incrementWeek();
35
        $this->getContainer()->get('event_dispatcher')->dispatch(CoreEvents::POST_WEEK_CHANGE, new GameDateEvent($gameDate));
36
        $this->getEntityManager()->flush();
37
    }
38
}
39