| Conditions | 2 |
| Paths | 2 |
| Total Lines | 68 |
| Code Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 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 | } |
||
| 111 |