Completed
Push — master ( a682ba...4851b3 )
by Paweł
40:50
created

LoadMenuNodesData::load()   B

Complexity

Conditions 6
Paths 10

Size

Total Lines 57
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 6.0061

Importance

Changes 0
Metric Value
dl 0
loc 57
ccs 17
cts 18
cp 0.9444
rs 8.7433
c 0
b 0
f 0
cc 6
eloc 37
nc 10
nop 1
crap 6.0061

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/*
4
 * This file is part of the Superdesk Web Publisher Fixtures Bundle.
5
 *
6
 * Copyright 2015 Sourcefabric z.ú. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2015 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Bundle\FixturesBundle\DataFixtures\ORM;
16
17
use Doctrine\Common\DataFixtures\FixtureInterface;
18
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
19
use SWP\Bundle\FixturesBundle\AbstractFixture;
20
use Doctrine\Common\Persistence\ObjectManager;
21
22
class LoadMenuNodesData extends AbstractFixture implements FixtureInterface, OrderedFixtureInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27 4
    public function load(ObjectManager $manager)
28
    {
29 4
        $env = $this->getEnvironment();
30
        $menuNodes = [
31
            'dev' => [
32
                [
33
                    'name' => 'home',
34
                    'label' => 'Home',
35
                    'locale' => 'en',
36
                ],
37 4
            ],
38
            'test' => [
39
                [
40
                    'name' => 'home',
41
                    'label' => 'Home',
42
                    'locale' => 'en',
43
                    'uri' => 'http://example.com/home',
44
                    'parent' => 1,
45
                ],
46
                [
47
                    'name' => 'contact',
48
                    'label' => 'Contact',
49
                    'locale' => 'en',
50
                    'uri' => 'http://example.com/contact',
51
                    'parent' => 1,
52
                ],
53
                [
54
                    'name' => 'sub',
55
                    'label' => 'Sub Contact',
56
                    'locale' => 'en',
57
                    'uri' => 'http://example.com/contact/sub',
58
                    'parent' => 3,
59
                ],
60
            ],
61
        ];
62
63 4
        if (isset($menuNodes[$env])) {
64 4
            $factory = $this->container->get('swp.factory.menu');
65 4
            $repository = $this->container->get('swp.repository.menu');
66 4
            foreach ($menuNodes[$env] as $menuNodeData) {
67 4
                $menuNode = $factory->createItem($menuNodeData['name']);
68 4
                $menuNode->setLabel($menuNodeData['label']);
69 4
                if (isset($menuNodeData['uri'])) {
70 4
                    $menuNode->setUri($menuNodeData['uri']);
71
                }
72 4
                if (isset($menuNodeData['route'])) {
73
                    $menuNode->setRoute($menuNodeData['route']);
74
                }
75 4
                if (isset($menuNodeData['parent'])) {
76 4
                    $menuNode->setParent($repository->getOneMenuItemById($menuNodeData['parent']));
77
                }
78
79 4
                $manager->persist($menuNode);
80 4
                $manager->flush();
81
            }
82
        }
83 4
    }
84
85 4
    public function getOrder()
86
    {
87 4
        return 5;
88
    }
89
}
90