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

LoadRoutesData::load()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 7
cts 7
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
crap 2
1
<?php
2
3
/*
4
 * This file is part of the Superdesk Web Publisher Fixtures Bundle.
5
 *
6
 * Copyright 2015 Sourcefabric z.u. 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 Doctrine\Common\Persistence\ObjectManager;
20
use SWP\Bundle\ContentBundle\Doctrine\ORM\Route;
21
use SWP\Bundle\FixturesBundle\AbstractFixture;
22
23
class LoadRoutesData extends AbstractFixture implements FixtureInterface, OrderedFixtureInterface
24
{
25
    const TEST_CACHE_TIME = 1;
26
    const TEST_CACHE_ROUTE_NAME = 'cache-route';
27
    const TEST_NO_CACHE_ROUTE_NAME = 'no-cache-route';
28
29
    /** @var array */
30
    protected $commonData = ['type' => 'content', 'content' => null];
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 2
    public function load(ObjectManager $manager)
36
    {
37 2
        $env = $this->getEnvironment();
38 2
        if ('test' === $env) {
39 2
            $this->loadRoute($manager, ['name' => self::TEST_NO_CACHE_ROUTE_NAME]);
40 2
            $this->loadRoute($manager, ['name' => self::TEST_CACHE_ROUTE_NAME, 'cacheTimeInSeconds' => self::TEST_CACHE_TIME]);
41 2
            $manager->flush();
42
        }
43 2
    }
44
45 2 View Code Duplication
    private function loadRoute($manager, $data)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
    {
47 2
        $data = array_merge($data, $this->commonData);
48 2
        $route = new Route();
49 2
        $route->setName($data['name']);
50 2
        $route->setType($data['type']);
51 2
        $route->setContent($data['content']);
52 2
        if (isset($data['cacheTimeInSeconds'])) {
53 2
            $route->setCacheTimeInSeconds($data['cacheTimeInSeconds']);
54
        }
55
56 2
        $route = $this->container->get('swp.service.route')->fillRoute($route);
57
58 2
        $manager->persist($route);
59 2
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 2
    public function getOrder()
65
    {
66 2
        return 3;
67
    }
68
}
69