Completed
Pull Request — develop (#50)
by Axel
02:57
created

LoadProjectData   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 10%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 4
c 2
b 1
f 0
lcom 0
cbo 4
dl 0
loc 37
ccs 2
cts 20
cp 0.1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setContainer() 0 3 1
A load() 0 18 2
A getOrder() 0 3 1
1
<?php
2
namespace Developtech\AgilityBundle\DataFixtures\ORM;
3
4
use Doctrine\Common\Persistence\ObjectManager;
5
use Doctrine\Common\DataFixtures\AbstractFixture;
6
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
7
use Symfony\Component\DependencyInjection\ContainerInterface;
8
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
9
10
use Developtech\AgilityBundle\Entity\Project;
11
12
class LoadProjectData extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface {
13
    /** @var ContainerInterface */
14
    private $container;
15
    /**
16
     * @param ContainerInterface $container
17
     */
18 1
    public function setContainer(ContainerInterface $container = null) {
19 1
        $this->container = $container;
20
    }
21
    /**
22
     * @param ObjectManager $manager
23
     */
24
    public function load(ObjectManager $manager) {
25
        $data = include('fixtures/projects.php');
26
        foreach ($data as $projectData)
27
        {
28
            $project =
29
                (new Project())
30
                ->setId($projectData['id'])
31
                ->setName($projectData['name'])
32
                ->setSlug($projectData['slug'])
33
                ->setDescription($projectData['description'])
34
                ->setCreatedAt(new \DateTime($projectData['created_at']))
35
            ;
36
            $manager->persist($project);
37
            $this->addReference("project-{$project->getId()}", $project);
38
        }
39
        $manager->flush();
40
        $manager->clear(Project::class);
41
    }
42
    /**
43
     * @return int
44
     */
45
    public function getOrder() {
46
        return 1;
47
    }
48
}
49