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

LoadSupplierData::load()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 68
Code Lines 50

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 50
nc 2
nop 1
dl 0
loc 68
rs 9.0909
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
 * LoadSupplierData 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;
17
18
use Doctrine\Bundle\FixturesBundle\Fixture;
19
use Doctrine\Common\Persistence\ObjectManager;
20
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
21
use App\Entity\Settings\Supplier;
22
use App\DataFixtures\LoadDiverseData;
23
24
/**
25
 * Load Supplier Data.
26
 *
27
 * @category DataFixtures
28
 */
29
class LoadSupplierData extends Fixture implements DependentFixtureInterface
30
{
31
    /**
32
     * Load data fixtures with the passed EntityManager.
33
     *
34
     * @param ObjectManager $manager
35
     */
36
    public function load(ObjectManager $manager)
37
    {
38
        /**
39
         * Serialization of phone numbers
40
         */
41
        $phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
42
43
        /**
44
         * Categories references
45
         */
46
        $surgele = $this->getReference('family-log3');
47
        $frais = $this->getReference('family-log4');
48
        $sec = $this->getReference('family-log5');
49
        $boissons = $this->getReference('family-log6');
50
51
        /**
52
         * Suppliers datas
53
         */
54
        $datas = [
55
            ['name' => 'Davigel', 'address' => '12, rue du gel', 'zipCode' => 75001,
56
            'town' => strtoupper('Paris'), 'phone' => $phoneUtil->parse('0140000001', 'FR'),
57
            'fax' => $phoneUtil->parse('0140000001', 'FR'),
58
            'mail' => '[email protected]', 'contact' => 'David Gel',
59
            'gsm' => $phoneUtil->parse('0160000001', 'FR'), 'family' => $surgele,
60
            'delayDeliv' => 2, 'orderDate' => [2, 5], ],
61
            ['name' => 'Davifrais', 'address' => '12, rue du frais',
62
            'zipCode' => 75001, 'town' => strtoupper('Paris'),
63
            'phone' => $phoneUtil->parse('0140000002', 'FR'),
64
            'fax' => $phoneUtil->parse('0140000002', 'FR'),
65
            'mail' => '[email protected]', 'contact' => 'David Frais',
66
            'gsm' => $phoneUtil->parse('0160000002', 'FR'), 'family' => $frais,
67
            'delayDeliv' => 2, 'orderDate' => [2, 5], ],
68
            ['name' => 'Davisec', 'address' => '12, rue du sec', 'zipCode' => 75001,
69
            'town' => strtoupper('Paris'), 'phone' => $phoneUtil->parse('0140000003', 'FR'),
70
            'fax' => $phoneUtil->parse('0140000003', 'FR'),
71
            'mail' => '[email protected]', 'contact' => 'David Sec',
72
            'gsm' => $phoneUtil->parse('0160000003', 'FR'), 'family' => $sec,
73
            'delayDeliv' => 3, 'orderDate' => [3], ],
74
            ['name' => 'Loire Boissons', 'address' => '12, rue de la soif',
75
            'zipCode' => 75001, 'town' => strtoupper('Paris'),
76
            'phone' => $phoneUtil->parse('0140000004', 'FR'),
77
            'fax' => $phoneUtil->parse('0140000004', 'FR'),
78
            'mail' => '[email protected]', 'contact' => 'Laurence Boisset',
79
            'gsm' => $phoneUtil->parse('0160000004', 'FR'), 'family' => $boissons,
80
            'delayDeliv' => 3, 'orderDate' => [5], ],
81
        ];
82
83
        foreach ($datas as $key => $data) {
84
            $supplier = new Supplier();
85
            $supplier->setName($data['name'])
86
                ->setAddress($data['address'])
87
                ->setZipCode($data['zipCode'])
88
                ->setTown($data['town'])
89
                ->setPhone($data['phone'])
90
                ->setFax($data['fax'])
91
                ->setEMail($data['mail'])
92
                ->setContact($data['contact'])
93
                ->setGsm($data['gsm'])
94
                ->setFamilyLog($data['family'])
95
                ->setDelaydeliv($data['delayDeliv'])
96
                ->setOrderdate($data['orderDate']);
97
98
            $manager->persist($supplier);
99
            $order = $key + 1;
100
            $this->addReference('supplier'.$order, $supplier);
101
        }
102
103
        $manager->flush();
104
    }
105
106
    public function getDependencies()
107
    {
108
        return [LoadDiverseData::class];
109
    }
110
}
111