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

LoadArticleData::load()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 122
Code Lines 104

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 104
nc 2
nop 1
dl 0
loc 122
rs 8
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
 * LoadArticleData Données 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\Article;
22
use App\Entity\Settings\Diverse\Material;
23
24
/**
25
 * Load Article Data.
26
 *
27
 * @category DataFixtures
28
 */
29
class LoadArticleData extends AbstractFixture implements OrderedFixtureInterface
30
{
31
    /**
32
     * Load data fixtures with the passed EntityManager.
33
     *
34
     * @param ObjectManager $manager
35
     */
36
    public function load(ObjectManager $manager)
37
    {
38
        // Références des fournisseurs
39
        $davigel = $this->getReference('supplier1');
40
        $davifrais = $this->getReference('supplier2');
41
        $davisec = $this->getReference('supplier3');
42
        $loireBoissons = $this->getReference('supplier4');
43
        // Références des catégories
44
        $surgele = $this->getReference('family-log3');
0 ignored issues
show
Unused Code introduced by
The assignment to $surgele is dead and can be removed.
Loading history...
45
        $frais = $this->getReference('family-log4');
46
        $sec = $this->getReference('family-log5');
47
        $boissons = $this->getReference('family-log6');
0 ignored issues
show
Unused Code introduced by
The assignment to $boissons is dead and can be removed.
Loading history...
48
        $fruitLegumesSurgele = $this->getReference('family-log7');
0 ignored issues
show
Unused Code introduced by
The assignment to $fruitLegumesSurgele is dead and can be removed.
Loading history...
49
        $patisseriesSurgele = $this->getReference('family-log8');
0 ignored issues
show
Unused Code introduced by
The assignment to $patisseriesSurgele is dead and can be removed.
Loading history...
50
        $viandeSurgele = $this->getReference('family-log9');
51
        $fruitLegumesFrais = $this->getReference('family-log10');
52
        $patisseriesFrais = $this->getReference('family-log11');
0 ignored issues
show
Unused Code introduced by
The assignment to $patisseriesFrais is dead and can be removed.
Loading history...
53
        $viandeFrais = $this->getReference('family-log12');
0 ignored issues
show
Unused Code introduced by
The assignment to $viandeFrais is dead and can be removed.
Loading history...
54
        $fruitLegumesSec = $this->getReference('family-log13');
0 ignored issues
show
Unused Code introduced by
The assignment to $fruitLegumesSec is dead and can be removed.
Loading history...
55
        $patisseriesSec = $this->getReference('family-log14');
0 ignored issues
show
Unused Code introduced by
The assignment to $patisseriesSec is dead and can be removed.
Loading history...
56
        $bieres = $this->getReference('family-log15');
0 ignored issues
show
Unused Code introduced by
The assignment to $bieres is dead and can be removed.
Loading history...
57
        $vins = $this->getReference('family-log16');
58
        // Références des zones de stockage
59
        $zoneSurgele = $this->getReference('zoneStorage1');
60
        $zoneFrais = $this->getReference('zoneStorage2');
61
        $zoneSec = $this->getReference('zoneStorage3');
62
        $zoneBoisson = $this->getReference('zoneStorage4');
63
        // Références des unités
64
        $boite = $this->getReference('unit1');
0 ignored issues
show
Unused Code introduced by
The assignment to $boite is dead and can be removed.
Loading history...
65
        $bouteille = $this->getReference('unit2');
66
        $carton = $this->getReference('unit3');
0 ignored issues
show
Unused Code introduced by
The assignment to $carton is dead and can be removed.
Loading history...
67
        $colis = $this->getReference('unit4');
0 ignored issues
show
Unused Code introduced by
The assignment to $colis is dead and can be removed.
Loading history...
68
        $kilogramme = $this->getReference('unit5');
69
        $litre = $this->getReference('unit6');
0 ignored issues
show
Unused Code introduced by
The assignment to $litre is dead and can be removed.
Loading history...
70
        $piece = $this->getReference('unit7');
71
        // Références des TVA
72
        $tvaReduit = $this->getReference('tva1');
73
        $tvaMoyen = $this->getReference('tva2');
0 ignored issues
show
Unused Code introduced by
The assignment to $tvaMoyen is dead and can be removed.
Loading history...
74
        $tvaLuxe = $this->getReference('tva3');
0 ignored issues
show
Unused Code introduced by
The assignment to $tvaLuxe is dead and can be removed.
Loading history...
75
        // Datas des articles
76
        $datas = [
77
            ['name' => 'Salade', 'supplier' => $davifrais,
78
            'familyLog' => $fruitLegumesFrais, 'zoneStorage' => $zoneFrais,
79
            'articleUnit.unitStorage' => $piece, 'unitWorking' => $kilogramme, 'price' => 2.99,
80
            'articleUnit.packaging' => 12, 'tva' => $tvaReduit, 'minStock' => 2, ],
81
            ['name' => 'Bavette 150gr', 'supplier' => $davigel,
82
            'familyLog' => $viandeSurgele, 'zoneStorage' => $zoneSurgele,
83
            'articleUnit.unitStorage' => $piece, 'unitWorking' => $piece, 'price' => 2.99,
84
            'articleUnit.packaging' => 28, 'tva' => $tvaReduit, 'minStock' => 2, ],
85
            ['name' => 'Baguettine', 'supplier' => $davigel,
86
            'familyLog' => $viandeSurgele, 'zoneStorage' => $zoneSurgele,
87
            'articleUnit.unitStorage' => $piece, 'unitWorking' => $piece, 'price' => 15.2,
88
            'articleUnit.packaging' => 90, 'tva' => $tvaReduit, 'minStock' => 20, ],
89
            ['name' => 'Steack haché 20%MG 120g', 'supplier' => $davigel,
90
            'familyLog' => $viandeSurgele, 'zoneStorage' => $zoneSurgele,
91
            'articleUnit.unitStorage' => $piece, 'unitWorking' => $piece, 'price' => 1.22,
92
            'articleUnit.packaging' => 50, 'tva' => $tvaReduit, 'minStock' => 12, ],
93
            ['name' => 'Ananas poche 2.3 KG', 'supplier' => $davisec,
94
            'familyLog' => $sec, 'zoneStorage' => $zoneSec,
95
            'articleUnit.unitStorage' => $piece, 'unitWorking' => $kilogramme, 'price' => 4.05,
96
            'articleUnit.packaging' => 4, 'tva' => $tvaReduit, 'minStock' => 3, ],
97
            ['name' => 'Appareil Champigons 2 KG', 'supplier' => $davifrais,
98
            'familyLog' => $frais, 'zoneStorage' => $zoneFrais,
99
            'articleUnit.unitStorage' => $piece, 'unitWorking' => $kilogramme, 'price' => 6.39,
100
            'articleUnit.packaging' => 4, 'tva' => $tvaReduit, 'minStock' => 2, ],
101
            ['name' => 'Bacon tranche Barq 88G', 'supplier' => $davifrais,
102
            'familyLog' => $frais, 'zoneStorage' => $zoneFrais,
103
            'articleUnit.unitStorage' => $piece, 'unitWorking' => $kilogramme, 'price' => 0.75,
104
            'articleUnit.packaging' => 6, 'tva' => $tvaReduit, 'minStock' => 2, ],
105
            ['name' => 'Beurre doux 8Gx125', 'supplier' => $davifrais,
106
            'familyLog' => $frais, 'zoneStorage' => $zoneFrais,
107
            'articleUnit.unitStorage' => $kilogramme, 'unitWorking' => $piece, 'price' => 6.83,
108
            'articleUnit.packaging' => 1, 'tva' => $tvaReduit, 'minStock' => 0.5, ],
109
            ['name' => 'Boule pour oeuf neige', 'supplier' => $davifrais,
110
            'familyLog' => $frais, 'zoneStorage' => $zoneFrais,
111
            'articleUnit.unitStorage' => $piece, 'unitWorking' => $piece, 'price' => 1.75,
112
            'articleUnit.packaging' => 6, 'tva' => $tvaReduit, 'minStock' => 2, ],
113
            ['name' => 'Champignons émincé 500G', 'supplier' => $davifrais,
114
            'familyLog' => $fruitLegumesFrais, 'zoneStorage' => $zoneFrais,
115
            'articleUnit.unitStorage' => $kilogramme, 'unitWorking' => $kilogramme,
116
            'price' => 3.17, 'articleUnit.packaging' => 3.5, 'tva' => $tvaReduit,
117
            'minStock' => 1, ],
118
            ['name' => 'Chorizo prétr. 500G', 'supplier' => $davifrais,
119
            'familyLog' => $fruitLegumesFrais, 'zoneStorage' => $zoneFrais,
120
            'articleUnit.unitStorage' => $kilogramme, 'unitWorking' => $kilogramme,
121
            'price' => 5.11, 'articleUnit.packaging' => 6, 'tva' => $tvaReduit, 'minStock' => 1, ],
122
            ['name' => 'V.RG Bourgueil 75cl', 'supplier' => $loireBoissons,
123
            'familyLog' => $vins, 'zoneStorage' => $zoneBoisson,
124
            'articleUnit.unitStorage' => $bouteille, 'unitWorking' => $bouteille,
125
            'price' => 5.11, 'articleUnit.packaging' => 6, 'tva' => $tvaReduit, 'minStock' => 3, ],
126
        ];
127
128
        foreach ($datas as $key => $data) {
129
            $article = new Article();
130
            $article->setName($data['name'])
131
                ->setSupplier($data['supplier'])
132
                ->setFamilyLog($data['familyLog'])
133
                ->addZoneStorage($data['zoneStorage'])
134
                // ->setArticleUnit($data['articleUnit.unitStorage'])
135
                // ->setArticleUnit($data['articleUnit.packaging'])
136
                // ->setUnitStorage($data['unitStorage'])
137
                ->setUnitWorking($data['unitWorking'])
138
                ->setPrice($data['price'])
139
                ->setTva($data['tva'])
140
                ->setMinStock($data['minStock']);
141
142
            $manager->persist($article);
143
            $order = $key + 1;
144
            $this->addReference('article'.$order, $article);
145
146
            $material = new Material();
147
            $material->setName($data['name'])
148
                ->setUnitWorking($data['unitWorking'])
149
                ->addArticle($this->getReference('article'.$order))
150
                ->setMultiple(0)
0 ignored issues
show
Bug introduced by
The method setMultiple() does not exist on App\Entity\Settings\Diverse\Material. ( Ignorable by Annotation )

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

150
                ->/** @scrutinizer ignore-call */ setMultiple(0)

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
151
                ->setActive(1);
152
153
            $manager->persist($material);
154
            $this->addReference('material'.$order, $material);
155
        }
156
157
        $manager->flush();
158
    }
159
160
    /**
161
     * Get the order of this fixture.
162
     *
163
     * @return int
164
     */
165
    public function getOrder()
166
    {
167
        return 6;
168
    }
169
}
170