1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the thealternativezurich/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(); |
|
|
|
|
55
|
|
|
if (null === $instance) { |
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
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
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.