Completed
Push — Recipes ( 630f49...c8afb0 )
by Laurent
12:15 queued 03:48
created

LoadDiverseData::getGroups()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
128
129
            $manager->persist($tva);
130
131
            $order = $key + 1;
132
            $this->addReference('tva'.$order, $tva);
133
        }
134
135
        $manager->flush();
136
    }
137
138
    public static function getGroups(): array
139
    {
140
        return ['settingsGroup'];
141
    }
142
}
143