Projects::load()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 59
Code Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 45
nc 2
nop 1
dl 0
loc 59
rs 9.2
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Copyright (c) 2017 Francois-Xavier Soubirou.
4
 *
5
 * This file is part of ci-report.
6
 *
7
 * ci-report is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * ci-report is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with ci-report. If not, see <http://www.gnu.org/licenses/>.
19
 */
20
declare(strict_types=1);
21
22
namespace App\DataFixtures\ORM;
23
24
use App\Entity\Project;
25
use App\Service\UtilService;
26
use Doctrine\Bundle\FixturesBundle\ORMFixtureInterface;
27
use Doctrine\Common\DataFixtures\AbstractFixture;
28
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
29
use Doctrine\Common\Persistence\ObjectManager;
30
31
/**
32
 * Project fixtures load class.
33
 *
34
 * @category  ci-report app
35
 *
36
 * @author    Francois-Xavier Soubirou <[email protected]>
37
 * @copyright 2017 Francois-Xavier Soubirou
38
 * @license   http://www.gnu.org/licenses/   GPLv3
39
 *
40
 * @see      https://www.ci-report.io
41
 */
42
class Projects extends AbstractFixture implements OrderedFixtureInterface, ORMFixtureInterface
43
{
44
    /**
45
     * Load data fixtures with the passed EntityManager.
46
     *
47
     * @param ObjectManager $manager The entity manager
48
     */
49
    public function load(ObjectManager $manager)
50
    {
51
        $utilService = new UtilService();
52
53
        $dataArray = array(
54
            array(
55
                'name' => 'Project One',
56
                'token' => '1f4ffb19e4b9-02278af07b7d-4e370a76f001',
57
                'email' => '[email protected]',
58
            ),
59
            array(
60
                'name' => 'Project Two',
61
                'token' => '1f4ffb19e4b9-02278af07b7d-4e370a76f002',
62
                'email' => '[email protected]',
63
            ),
64
            array(
65
                'name' => 'Project Three',
66
                'token' => '1f4ffb19e4b9-02278af07b7d-4e370a76f003',
67
                'email' => '[email protected]',
68
            ),
69
            array(
70
                'name' => 'Project Four',
71
                'token' => '1f4ffb19e4b9-02278af07b7d-4e370a76f004',
72
                'email' => '[email protected]',
73
            ),
74
            array(
75
                'name' => 'Project Five',
76
                'token' => '1f4ffb19e4b9-02278af07b7d-4e370a76f005',
77
                'email' => '[email protected]',
78
            ),
79
            array(
80
                'name' => 'Project Six',
81
                'token' => '1f4ffb19e4b9-02278af07b7d-4e370a76f006',
82
                'email' => '[email protected]',
83
            ),
84
            array(
85
                'name' => 'Project Seven',
86
                'token' => '1f4ffb19e4b9-02278af07b7d-4e370a76f007',
87
                'email' => '[email protected]',
88
            ),
89
            array(
90
                'name' => 'Project Eight',
91
                'token' => '1f4ffb19e4b9-02278af07b7d-4e370a76f008',
92
                'email' => '[email protected]',
93
            ),
94
        );
95
        $objectList = array();
96
        foreach ($dataArray as $i => $data) {
97
            $objectList[$i] = new Project();
98
            $objectList[$i]->setName($data['name']);
99
            $objectList[$i]->setRefid($utilService->toAscii($data['name']));
100
            $objectList[$i]->setToken($data['token']);
101
            $objectList[$i]->setEmail($data['email']);
102
103
            $manager->persist($objectList[$i]);
104
            $ref = strtolower(str_replace(' ', '', $data['name'])).'-project';
105
            $this->addReference($ref, $objectList[$i]);
106
        }
107
        $manager->flush();
108
    }
109
110
    /**
111
     * Get the order of this fixture.
112
     *
113
     * @return int
114
     */
115
    public function getOrder(): int
116
    {
117
        return 10;
118
    }
119
}
120