Passed
Push — master ( cc6223...026396 )
by Florian
02:39
created

BaseFixture::fillAddress()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 11
c 0
b 0
f 0
rs 10
nc 2
nop 1
cc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A BaseFixture::getRandomInstance() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of the feedback project.
5
 *
6
 * (c) Florian Moser <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace App\DataFixtures\Base;
13
14
use Doctrine\Bundle\FixturesBundle\Fixture;
15
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
16
use Doctrine\Persistence\ObjectManager;
17
use Faker\Factory;
18
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
19
use Symfony\Component\DependencyInjection\ContainerInterface;
20
21
abstract class BaseFixture extends Fixture implements OrderedFixtureInterface, ContainerAwareInterface
22
{
23
    /* @var ContainerInterface $container */
24
    private $container;
25
26
    public function setContainer(ContainerInterface $container = null)
27
    {
28
        $this->container = $container;
29
    }
30
31
    protected function getTranslator()
32
    {
33
        return $this->container->get('translator');
34
    }
35
36
    /**
37
     * @return \Faker\Generator
38
     */
39
    protected function getFaker()
40
    {
41
        return Factory::create('de_CH');
42
    }
43
44
    /**
45
     * create random instances.
46
     *
47
     * @param $count
48
     *
49
     * @throws \Exception
50
     */
51
    protected function loadSomeRandoms(ObjectManager $manager, $count = 5)
52
    {
53
        for ($i = 0; $i < $count; ++$i) {
54
            $instance = $this->getRandomInstance();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $instance is correct as $this->getRandomInstance() targeting App\DataFixtures\Base\Ba...re::getRandomInstance() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
55
            if ($instance === null) {
56
                throw new \Exception('you need to override getRandomInstance to return an instance before you can use this function');
57
            }
58
            $manager->persist($instance);
59
        }
60
    }
61
62
    /**
63
     * create an instance with all random values.
64
     *
65
     * @return mixed
66
     */
67
    protected function getRandomInstance()
68
    {
69
        return null;
70
    }
71
}
72