LoadTranslationData::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 i18n bundle.
5
 *
6
 * See LICENSE file in the root of the bundle. Webcook
7
 */
8
9
namespace Webcook\Cms\I18nBundle\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\I18nBundle\Entity\Translation;
15
use Webcook\Cms\I18nBundle\Entity\Language;
16
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
17
use Symfony\Component\DependencyInjection\ContainerInterface;
18
19
/**
20
 * Translation fixtures for tests.
21
 */
22
class LoadTranslationData implements FixtureInterface, ContainerAwareInterface, OrderedFixtureInterface
23
{
24
    /**
25
     * System container.
26
     *
27
     * @var ContainerInterface
28
     */
29
    private $container;
30
31
    /**
32
     * Entity manager.
33
     *
34
     * @var ObjectManager
35
     */
36
    private $manager;
37
38
    /**
39
     * {@inheritDoc}
40
     */
41 7
    public function setContainer(ContainerInterface $container = null)
42
    {
43 7
        $this->container = $container;
44 7
    }
45
46
    /**
47
     * {@inheritDoc}
48
     */
49 7
    public function load(ObjectManager $manager)
50
    {
51 7
        $this->manager = $manager;
52
53 7
        $czechLanguage = $manager->getRepository('\Webcook\Cms\I18nBundle\Entity\Language')->findAll()[0];
54 7
        $englishLanguage = $manager->getRepository('\Webcook\Cms\I18nBundle\Entity\Language')->findAll()[1];
55
56 7
        $this->addTranslation('common.test.translation', $englishLanguage, 'This is test translation.');
57 7
        $this->addTranslation('common.test.translation', $czechLanguage, 'Test prekladace.');
58
        
59 7
        $this->manager->flush();
60 7
    }
61
62 7
    private function addTranslation(String $key, Language $language, String $translationText, String $domain = 'messages')
63
    {
64 7
        $translation = new Translation();
65 7
        $translation->setKey($key)
66 7
                    ->setLanguage($language)
67 7
                    ->setCatalogue($domain)
68 7
                    ->setTranslation($translationText);
69
70 7
        $this->manager->persist($translation);
71 7
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76 7
    public function getOrder()
77
    {
78 7
        return 1;
79
    }
80
}
81