FixtureService   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 6
dl 0
loc 41
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createFixtures() 0 20 2
1
<?php
2
3
namespace OSS\CoreBundle\Services;
4
5
use Doctrine\ORM\EntityManager;
6
use OSS\CoreBundle\Entity\Fixture;
7
use OSS\CoreBundle\Entity\League;
8
use OSS\CoreBundle\FixtureGenerator\Generator;
9
10
class FixtureService
11
{
12
    /**
13
     * @var EntityManager
14
     */
15
    private $entityManager;
16
17
    /**
18
     * @param EntityManager $entityManager
19
     */
20
    public function __construct(EntityManager $entityManager)
21
    {
22
        $this->entityManager = $entityManager;
23
    }
24
25
    /**
26
     * @param int $season
27
     *
28
     * @throws \Exception
29
     */
30
    public function createFixtures($season)
31
    {
32
        /** @var League $league */
33
        $league = $this->entityManager->getRepository('CoreBundle:League')->findOneBy(array());
34
        $generator = new Generator(count($league->getTeams()));
35
        $matches = $generator->createFixtures();
36
        $listOfTeams = $league->getTeams();
37
38
        foreach ($matches as $match) {
39
            $fixture = new Fixture();
40
            $fixture->setSeason($season);
41
            $fixture->setWeek($match->getWeek());
42
            $fixture->setTeamHome($listOfTeams[$match->getTeamHome() - 1]);
43
            $fixture->setTeamAway($listOfTeams[$match->getTeamAway() - 1]);
44
            $fixture->setLeague($league);
45
46
            $this->entityManager->persist($fixture);
47
        }
48
        $this->entityManager->flush();
49
    }
50
}
51