LayoutBlocks   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 51
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setContainer() 0 4 1
A getOrder() 0 4 1
A resource() 0 5 1
B load() 0 24 3
1
<?php
2
3
namespace AppBundle\Fixture\Cms;
4
5
use AppBundle\Entity\CmsBlock;
6
use Doctrine\Common\DataFixtures\FixtureInterface;
7
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
8
use Doctrine\Common\Persistence\ObjectManager;
9
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
10
use Symfony\Component\DependencyInjection\ContainerInterface;
11
12
class LayoutBlocks implements FixtureInterface, OrderedFixtureInterface, ContainerAwareInterface
13
{
14
    private $container;
15
16
    /**
17
     * {@inheritDoc}
18
     */
19
    public function setContainer(ContainerInterface $container = null)
20
    {
21
        $this->container = $container;
22
    }
23
24
    /**
25
     * {@inheritDoc}
26
     */
27
    public function getOrder()
28
    {
29
        return 0;
30
    }
31
32
    private function resource($name)
33
    {
34
        $location = $this->container->get('kernel')->locateResource("@AppBundle/Resources/views/blocks/layout/{$name}.html.twig");
35
        return file_get_contents($location);
36
    }
37
38
    public function load(ObjectManager $manager)
39
    {
40
        $blocks = [
41
            'footer',
42
        ];
43
44
        foreach ($blocks as $alias) {
45
            $block = new CmsBlock();
46
            $block->setAlias($alias);
47
            $block->setName(implode(' ', array_map('ucfirst', explode('_', $alias))));
48
            $block->setContent($this->resource($alias));
49
            $manager->persist($block);
50
        }
51
52
        foreach (['css', 'js'] as $alias) {
53
            $block = new CmsBlock();
54
            $block->setAlias($alias);
55
            $block->setName(implode(' ', array_map('ucfirst', explode('_', $alias))));
56
            $block->setContent("/* cms block for {$alias} */");
57
            $manager->persist($block);
58
        }
59
60
        $manager->flush();
61
    }
62
}
63