LoadUserData::getFixtures()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 26
rs 8.8571
cc 2
eloc 19
nc 2
nop 0
1
<?php
2
3
/**
4
 * @link http://symfony.com/doc/current/bundles/DoctrineFixturesBundle/index.html
5
 * @link https://github.com/nelmio/alice
6
 * @link https://github.com/fzaninotto/Faker
7
 */
8
9
namespace AppBundle\DataFixtures\ORM;
10
11
use Doctrine\Common\DataFixtures\FixtureInterface;
12
use Doctrine\Common\Persistence\ObjectManager;
13
use Nelmio\Alice\Fixtures;
14
15
class LoadUserData implements FixtureInterface
16
{
17
    public function load(ObjectManager $manager)
18
    {
19
        Fixtures::load($this->getFixtures(), $manager, ['providers' => [$this]]);
20
    }
21
22
    public function getFixtures()
0 ignored issues
show
Coding Style introduced by
getFixtures uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
23
    {
24
        $kernel = $GLOBALS['kernel'];
25
        $env = $kernel->getEnvironment();
26
27
        echo "\nEnvironment is: " . $env . "\n\n";
28
29
        if ($env == 'test') {
30
            return [
31
                __DIR__.'/test/role.yml',
32
                __DIR__.'/test/tag.yml',
33
                __DIR__.'/test/category.yml',
34
                __DIR__.'/test/user.yml',
35
                __DIR__.'/test/article.yml',
36
                __DIR__.'/test/comment.yml',
37
            ];
38
        }
39
        return [
40
            __DIR__.'/dev/role.yml',
41
            __DIR__.'/dev/tag.yml',
42
            __DIR__.'/dev/category.yml',
43
            __DIR__.'/dev/user.yml',
44
            __DIR__.'/dev/article.yml',
45
            __DIR__.'/dev/comment.yml',
46
        ];
47
    }
48
49
    public function role($count)
50
    {
51
        $roles = [
52
            'admin',
53
            'moderator',
54
            'user',
55
            'anonymous',
56
        ];
57
58
        return $roles[$count-1];
59
    }
60
61
    public function picture()
62
    {
63
        $picture = [
64
            'balloon',
65
            'buildings',
66
            'people',
67
        ];
68
69
        return $picture[array_rand($picture)];
70
    }
71
72
    public function photo()
73
    {
74
        $photo = [
75
            'user1.png',
76
            'user2.png',
77
            'user3.png',
78
            'user4.png',
79
            'user5.png',
80
        ];
81
82
        return $photo[array_rand($photo)];
83
    }
84
}