LoadLanguageData::addLanguage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

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 1
eloc 6
nc 1
nop 3
crap 1
1
<?php
2
3
/**
4
 * This file is part of Webcook common 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\Language;
15
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
16
use Symfony\Component\DependencyInjection\ContainerInterface;
17
18
/**
19
 * Language fixtures for tests.
20
 */
21
class LoadLanguageData implements FixtureInterface, ContainerAwareInterface, OrderedFixtureInterface
22
{
23
    /**
24
     * System container.
25
     *
26
     * @var ContainerInterface
27
     */
28
    private $container;
29
30
    /**
31
     * Entity manager.
32
     *
33
     * @var ObjectManager
34
     */
35
    private $manager;
36
37
    /**
38
     * {@inheritDoc}
39
     */
40 14
    public function setContainer(ContainerInterface $container = null)
41
    {
42 14
        $this->container = $container;
43 14
    }
44
45
    /**
46
     * {@inheritDoc}
47
     */
48 14
    public function load(ObjectManager $manager)
49
    {
50 14
        $this->manager = $manager;
51
52 14
        $this->addLanguage('Čeština', 'cs', true);
53 14
        $this->addLanguage('English', 'en');
54 14
        $this->addLanguage('Deutsch', 'de');
55
        
56 14
        $this->manager->flush();
57 14
    }
58
59 14
    private function addLanguage(String $title, String $abbr, Bool $default = false)
60
    {
61 14
        $language = new Language();
62 14
        $language->setTitle($title)
63 14
                    ->setLocale($abbr)
64 14
                    ->setDefault($default);
0 ignored issues
show
Documentation introduced by
$default is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
65
66 14
        $this->manager->persist($language);
67 14
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72 14
    public function getOrder()
73
    {
74 14
        return 0;
75
    }
76
}
77