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

LoadSeparateArticlesData::getOrder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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\PHPCR;
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\ODM\PHPCR\Article;
21
use SWP\Bundle\ContentBundle\Model\ArticleInterface;
22
use SWP\Bundle\FixturesBundle\AbstractFixture;
23
24
class LoadSeparateArticlesData extends AbstractFixture implements FixtureInterface, OrderedFixtureInterface
25
{
26
    private $manager;
27
    private $defaultTenantPrefix;
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 View Code Duplication
    public function load(ObjectManager $manager)
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...
33
    {
34
        $this->manager = $manager;
35
        $env = $this->getEnvironment();
36
37
        $this->defaultTenantPrefix = $this->getTenantPrefix();
38
39
        $this->loadArticles($env, $manager);
40
41
        $manager->flush();
42
    }
43
44
    /**
45
     * Sets articles manually (not via Alice) for test env due to fatal error:
46
     * Method PHPCRProxies\__CG__\Doctrine\ODM\PHPCR\Document\Generic::__toString() must not throw an exception.
47
     */
48
    public function loadArticles($env, $manager)
49
    {
50
        $articles = [
51
            'test' => [
52
                [
53
                    'title' => 'Test news article',
54
                    'content' => 'Test news article content',
55
                    'parent' => $this->defaultTenantPrefix.'/content',
56
                    'locale' => 'en',
57
                ],
58
                [
59
                    'title' => 'Test content article',
60
                    'content' => 'Test article content',
61
                    'parent' => $this->defaultTenantPrefix.'/content',
62
                    'locale' => 'en',
63
                ],
64
            ],
65
        ];
66
67
        if (isset($articles[$env])) {
68
            foreach ($articles[$env] as $articleData) {
69
                $article = new Article();
70
                $article->setParent($manager->find(null, $articleData['parent']));
71
                $article->setTitle($articleData['title']);
72
                $article->setBody($articleData['content']);
73
                $article->setLocale($articleData['locale']);
74
                $article->setPublishedAt(new \DateTime());
75
                $article->setPublishable(true);
76
                $article->setStatus(ArticleInterface::STATUS_PUBLISHED);
77
78
                $manager->persist($article);
79
            }
80
81
            $manager->flush();
82
        }
83
    }
84
85
    /**
86
     * {@inheritdoc}
87
     */
88
    public function getOrder()
89
    {
90
        return 2;
91
    }
92
}
93