Completed
Push — Recipes ( c0466a...7632b6 )
by Laurent
04:22
created

LoadDiverseData::load()   B

Complexity

Conditions 6
Paths 24

Size

Total Lines 93
Code Lines 66

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 66
nc 24
nop 1
dl 0
loc 93
rs 8.1195
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
 * LoadDiverseData Données de configuration de l'application GLSR.
4
 *
5
 * PHP Version 7
6
 *
7
 * @author    Quétier Laurent <[email protected]>
8
 * @copyright 2018 Dev-Int GLSR
9
 * @license   http://opensource.org/licenses/gpl-license.php GNU Public License
10
 *
11
 * @version GIT: $Id$
12
 *
13
 * @see https://github.com/Dev-Int/glsr
14
 */
15
16
namespace App\DataFixtures\ORM;
17
18
use Doctrine\Common\DataFixtures\AbstractFixture;
19
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
20
use Doctrine\Common\Persistence\ObjectManager;
21
use App\Entity\Settings\Diverse\FamilyLog;
22
use App\Entity\Settings\Diverse\ZoneStorage;
23
use App\Entity\Settings\Diverse\Unit;
24
use App\Entity\Settings\Diverse\Tva;
25
26
/**
27
 * LoadDiverse Data.
28
 *
29
 * @category DataFixtures
30
 */
31
class LoadDiverseData extends AbstractFixture implements OrderedFixtureInterface
32
{
33
    /**
34
     * Load data fixtures with the passed EntityManager.
35
     *
36
     * @param ObjectManager $manager
37
     */
38
    public function load(ObjectManager $manager)
39
    {
40
        // Load FamilyLog
41
        $familyArray = [
42
            ['name' => 'Alimentaire'],
43
            ['name' => 'Non alimentaire'],
44
            ['name' => 'Surgelé', 'parent' => 1],
45
            ['name' => 'Frais', 'parent' => 1],
46
            ['name' => 'Sec', 'parent' => 1],
47
            ['name' => 'Boissons', 'parent' => 1],
48
            ['name' => 'Fruits&Légumes', 'parent' => 3],
49
            ['name' => 'Patisseries', 'parent' => 3],
50
            ['name' => 'Viandes', 'parent' => 3],
51
            ['name' => 'Fruits&Légumes', 'parent' => 4],
52
            ['name' => 'Patisseries', 'parent' => 4],
53
            ['name' => 'Viandes', 'parent' => 4],
54
            ['name' => 'Fruits&Légumes', 'parent' => 5],
55
            ['name' => 'Patisseries', 'parent' => 5],
56
            ['name' => 'Bières', 'parent' => 6],
57
            ['name' => 'Vins', 'parent' => 6],
58
        ];
59
        foreach ($familyArray as $key => $family) {
60
            $familyLog = new FamilyLog();
61
            $familyLog->setName($family['name']);
62
            if (isset($family['parent'])) {
63
                $parent = $familyLogs[$family['parent'] - 1];
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $familyLogs seems to be defined later in this foreach loop on line 66. Are you sure it is defined here?
Loading history...
64
                $familyLog->setParent($parent);
65
            }
66
            $familyLogs[$key] = $familyLog;
67
68
            $manager->persist($familyLog);
69
70
            $order = $key + 1;
71
            $this->addReference('family-log'.$order, $familyLog);
72
        }
73
74
        // Load ZoneStorage
75
        $zoneArray = [
76
            ['name' => 'Chambre négative'],
77
            ['name' => 'Chambre posistive'],
78
            ['name' => 'Réserve sèche'],
79
            ['name' => 'Réserve boissons'],
80
            ['name' => 'Armoire à boissons'],
81
            ['name' => 'Caisse'],
82
        ];
83
        foreach ($zoneArray as $key => $zone) {
84
            $zoneStorage = new ZoneStorage();
85
            $zoneStorage->setName($zone['name']);
86
87
            $manager->persist($zoneStorage);
88
89
            $order = $key + 1;
90
            $this->addReference('zoneStorage'.$order, $zoneStorage);
91
        }
92
93
        // Load Unit
94
        $unitArray = [
95
            ['name' => 'Boite', 'abbr' => 'BOI'],
96
            ['name' => 'Bouteille', 'abbr' => 'BTE'],
97
            ['name' => 'Carton', 'abbr' => 'CAR'],
98
            ['name' => 'Colis', 'abbr' => 'CLS'],
99
            ['name' => 'Kilogramme', 'abbr' => 'KG'],
100
            ['name' => 'Litre', 'abbr' => 'L'],
101
            ['name' => 'Pièce', 'abbr' => 'PIE'],
102
        ];
103
        foreach ($unitArray as $key => $unit) {
104
            $unitStorage = new Unit();
105
            $unitStorage->setName($unit['name'])
106
                ->setAbbr($unit['abbr']);
107
108
            $manager->persist($unitStorage);
109
110
            $order = $key + 1;
111
            $this->addReference('unit'.$order, $unitStorage);
112
        }
113
114
        // Load Tva
115
        $tvaArray = [
116
            ['rate' => '0.055'],
117
            ['rate' => '0.1'],
118
            ['rate' => '0.2'],
119
        ];
120
        foreach ($tvaArray as $key => $tvaRate) {
121
            $tva = new Tva();
122
            $tva->setRate($tvaRate['rate']);
0 ignored issues
show
Bug introduced by
$tvaRate['rate'] of type string is incompatible with the type App\Entity\Settings\Diverse\decimal expected by parameter $rate of App\Entity\Settings\Diverse\Tva::setRate(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

122
            $tva->setRate(/** @scrutinizer ignore-type */ $tvaRate['rate']);
Loading history...
123
124
            $manager->persist($tva);
125
126
            $order = $key + 1;
127
            $this->addReference('tva'.$order, $tva);
128
        }
129
130
        $manager->flush();
131
    }
132
133
    /**
134
     * Get the order of this fixture.
135
     *
136
     * @return int
137
     */
138
    public function getOrder()
139
    {
140
        return 4;
141
    }
142
}
143