LoadResourcesData::setContainer()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
 * This file is part of Webcook security bundle.
5
 *
6
 * See LICENSE file in the root of the bundle. Webcook 
7
 */
8
9
namespace Webcook\Cms\SecurityBundle\DataFixtures\ORM;
10
11
use Doctrine\Common\DataFixtures\FixtureInterface;
12
use Doctrine\Common\Persistence\ObjectManager;
13
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
14
use Webcook\Cms\SecurityBundle\Entity\Resource;
15
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
16
use Symfony\Component\DependencyInjection\ContainerInterface;
17
use Webcook\Cms\SecurityBundle\Common\SecurityHelper;
18
19
/**
20
 * Resources fixtures for tests.
21
 */
22
class LoadResourcesData implements FixtureInterface, ContainerAwareInterface, OrderedFixtureInterface
23
{
24
    /**
25
     * System container.
26
     *
27
     * @var ContainerInterface
28
     */
29
    private $container;
30
31
    /**
32
     * Set container
33
     *
34
     * {@inheritDoc}
35
     *
36
     * @param ContainerInterface $container [description]
37
     */
38 49
    public function setContainer(ContainerInterface $container = null)
39
    {
40 49
        $this->container = $container;
41 49
    }
42
43
    /**
44
     * Load fixtures into db.
45
     *
46
     * {@inheritDoc}
47
     *
48
     * @param ObjectManager $manager
49
     */
50 49
    public function load(ObjectManager $manager)
51
    {
52 49
        $resources = SecurityHelper::getResourcesNames($this->container->getParameter('resources_path'));
53
54 49
        foreach ($resources as $resourceName) {
55 49
            $resource = new Resource();
56 49
            $resource->setName($resourceName);
57
58 49
            $manager->persist($resource);
59
        }
60
61 49
        $manager->flush();
62 49
    }
63
64
    /**
65
     * Get order of fixture.
66
     *
67
     * {@inheritdoc}
68
     */
69 49
    public function getOrder()
70
    {
71 49
        return 0;
72
    }
73
}
74