Completed
Push — Recipes ( 43b996...9c2236 )
by Laurent
03:16
created

LoadDiverseData::load()   B

Complexity

Conditions 6
Paths 24

Size

Total Lines 62
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 31
nc 24
nop 1
dl 0
loc 62
rs 8.8017
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;
17
18
use Doctrine\Bundle\FixturesBundle\Fixture;
19
use Doctrine\Common\Persistence\ObjectManager;
20
use App\Entity\Settings\Diverse\FamilyLog;
21
use App\Entity\Settings\Diverse\ZoneStorage;
22
use App\Entity\Settings\Diverse\Unit;
23
use App\Entity\Settings\Diverse\Tva;
24
25
/**
26
 * LoadDiverse Data.
27
 *
28
 * @category DataFixtures
29
 */
30
class LoadDiverseData extends Fixture
31
{
32
    protected $familyArray = [
33
        ['name' => 'Alimentaire'],
34
        ['name' => 'Non alimentaire'],
35
        ['name' => 'Surgelé', 'parent' => 1],
36
        ['name' => 'Frais', 'parent' => 1],
37
        ['name' => 'Sec', 'parent' => 1],
38
        ['name' => 'Boissons', 'parent' => 1],
39
        ['name' => 'Fruits&Légumes', 'parent' => 3],
40
        ['name' => 'Patisseries', 'parent' => 3],
41
        ['name' => 'Viandes', 'parent' => 3],
42
        ['name' => 'Fruits&Légumes', 'parent' => 4],
43
        ['name' => 'Patisseries', 'parent' => 4],
44
        ['name' => 'Viandes', 'parent' => 4],
45
        ['name' => 'Fruits&Légumes', 'parent' => 5],
46
        ['name' => 'Patisseries', 'parent' => 5],
47
        ['name' => 'Bières', 'parent' => 6],
48
        ['name' => 'Vins', 'parent' => 6],
49
    ];
50
    protected $zoneArray = [
51
        ['name' => 'Chambre négative'],
52
        ['name' => 'Chambre posistive'],
53
        ['name' => 'Réserve sèche'],
54
        ['name' => 'Réserve boissons'],
55
        ['name' => 'Armoire à boissons'],
56
        ['name' => 'Caisse'],
57
    ];
58
    protected $unitArray = [
59
        ['name' => 'Boite', 'abbr' => 'BOI'],
60
        ['name' => 'Bouteille', 'abbr' => 'BTE'],
61
        ['name' => 'Carton', 'abbr' => 'CAR'],
62
        ['name' => 'Colis', 'abbr' => 'CLS'],
63
        ['name' => 'Kilogramme', 'abbr' => 'KG'],
64
        ['name' => 'Litre', 'abbr' => 'L'],
65
        ['name' => 'Pièce', 'abbr' => 'PIE'],
66
    ];
67
    protected $tvaArray = [
68
        ['rate' => '0.055'],
69
        ['rate' => '0.1'],
70
        ['rate' => '0.2'],
71
    ];
72
73
    /**
74
     * Load data fixtures with the passed EntityManager.
75
     *
76
     * @param ObjectManager $manager
77
     */
78
    public function load(ObjectManager $manager)
79
    {
80
        /**
81
         * Load FamilyLog
82
         */
83
        $familyLogs = [];
84
        foreach ($this->familyArray as $key => $family) {
85
            $familyLog = new FamilyLog();
86
            $familyLog->setName($family['name']);
87
            if (isset($family['parent'])) {
88
                $parent = $familyLogs[$family['parent'] - 1];
89
                $familyLog->setParent($parent);
90
            }
91
            $familyLogs[$key] = $familyLog;
92
93
            $manager->persist($familyLog);
94
95
            $order = $key + 1;
96
            $this->addReference('family-log'.$order, $familyLog);
97
        }
98
99
        /**
100
         * Load ZoneStorage
101
         */
102
        foreach ($this->zoneArray as $key => $zone) {
103
            $zoneStorage = new ZoneStorage();
104
            $zoneStorage->setName($zone['name']);
105
106
            $manager->persist($zoneStorage);
107
108
            $order = $key + 1;
109
            $this->addReference('zoneStorage'.$order, $zoneStorage);
110
        }
111
112
        /**
113
         * Load Unit
114
         */
115
        foreach ($this->unitArray as $key => $unit) {
116
            $unitStorage = new Unit();
117
            $unitStorage->setName($unit['name'])
118
                ->setAbbr($unit['abbr']);
119
120
            $manager->persist($unitStorage);
121
122
            $order = $key + 1;
123
            $this->addReference('unit'.$order, $unitStorage);
124
        }
125
126
        /**
127
         * Load Tva
128
         */
129
        foreach ($this->tvaArray as $key => $tvaRate) {
130
            $tva = new Tva();
131
            $tva->setRate((double)$tvaRate['rate']);
132
133
            $manager->persist($tva);
134
135
            $order = $key + 1;
136
            $this->addReference('tva'.$order, $tva);
137
        }
138
139
        $manager->flush();
140
    }
141
}
142