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

LoadSupplierData::load()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 60
Code Lines 50

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 50
nc 2
nop 1
dl 0
loc 60
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\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\Supplier;
22
23
/**
24
 * Load Supplier Data.
25
 *
26
 * @category DataFixtures
27
 */
28
class LoadSupplierData extends AbstractFixture implements OrderedFixtureInterface
29
{
30
    /**
31
     * Load data fixtures with the passed EntityManager.
32
     *
33
     * @param ObjectManager $manager
34
     */
35
    public function load(ObjectManager $manager)
36
    {
37
        // Serialisation des numéros de téléphone
38
        $phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
39
        // Références des catégories
40
        $surgele = $this->getReference('family-log3');
41
        $frais = $this->getReference('family-log4');
42
        $sec = $this->getReference('family-log5');
43
        $boissons = $this->getReference('family-log6');
44
        // Datas des suppliers
45
        $datas = [
46
            ['name' => 'Davigel', 'address' => '12, rue du gel', 'zipCode' => 75001,
47
            'town' => 'Paris', 'phone' => $phoneUtil->parse('0140000001', 'FR'),
48
            'fax' => $phoneUtil->parse('0140000001', 'FR'),
49
            'mail' => '[email protected]', 'contact' => 'David Gel',
50
            'gsm' => $phoneUtil->parse('0160000001', 'FR'), 'family' => $surgele,
51
            'delayDeliv' => 2, 'orderDate' => [2, 5], ],
52
            ['name' => 'Davifrais', 'address' => '12, rue du frais',
53
            'zipCode' => 75001, 'town' => 'Paris',
54
            'phone' => $phoneUtil->parse('0140000002', 'FR'),
55
            'fax' => $phoneUtil->parse('0140000002', 'FR'),
56
            'mail' => '[email protected]', 'contact' => 'David Frais',
57
            'gsm' => $phoneUtil->parse('0160000002', 'FR'), 'family' => $frais,
58
            'delayDeliv' => 2, 'orderDate' => [2, 5], ],
59
            ['name' => 'Davisec', 'address' => '12, rue du sec', 'zipCode' => 75001,
60
            'town' => 'Paris', 'phone' => $phoneUtil->parse('0140000003', 'FR'),
61
            'fax' => $phoneUtil->parse('0140000003', 'FR'),
62
            'mail' => '[email protected]', 'contact' => 'David Sec',
63
            'gsm' => $phoneUtil->parse('0160000003', 'FR'), 'family' => $sec,
64
            'delayDeliv' => 3, 'orderDate' => [3], ],
65
            ['name' => 'Loire Boissons', 'address' => '12, rue de la soif',
66
            'zipCode' => 75001, 'town' => 'Paris',
67
            'phone' => $phoneUtil->parse('0140000004', 'FR'),
68
            'fax' => $phoneUtil->parse('0140000004', 'FR'),
69
            'mail' => '[email protected]', 'contact' => 'David Sec',
70
            'gsm' => $phoneUtil->parse('0160000004', 'FR'), 'family' => $boissons,
71
            'delayDeliv' => 3, 'orderDate' => [5], ],
72
        ];
73
74
        foreach ($datas as $key => $data) {
75
            $supplier = new Supplier();
76
            $supplier->setName($data['name'])
77
                ->setAddress($data['address'])
78
                ->setZipCode($data['zipCode'])
79
                ->setTown($data['town'])
80
                ->setPhone($data['phone'])
81
                ->setFax($data['fax'])
82
                ->setMail($data['mail'])
0 ignored issues
show
Bug introduced by
The method setMail() does not exist on App\Entity\Settings\Supplier. Did you maybe mean setEmail()? ( Ignorable by Annotation )

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

82
                ->/** @scrutinizer ignore-call */ setMail($data['mail'])

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...
83
                ->setContact($data['contact'])
84
                ->setGsm($data['gsm'])
85
                ->setFamilyLog($data['family'])
86
                ->setDelaydeliv($data['delayDeliv'])
87
                ->setOrderdate($data['orderDate']);
88
89
            $manager->persist($supplier);
90
            $order = $key + 1;
91
            $this->addReference('supplier'.$order, $supplier);
92
        }
93
94
        $manager->flush();
95
    }
96
97
    /**
98
     * Get the order of this fixture.
99
     *
100
     * @return int
101
     */
102
    public function getOrder()
103
    {
104
        return 5;
105
    }
106
}
107