| Conditions | 6 | 
| Paths | 24 | 
| Total Lines | 93 | 
| Code Lines | 66 | 
| 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 | ||
| 38 | public function load(ObjectManager $manager) | ||
| 39 |     { | ||
| 40 | // Load FamilyLog | ||
| 41 | $familyArray = [ | ||
| 42 | ['name' => 'Alimentaire'], | ||
| 43 | ['name' => 'Non alimentaire'], | ||
| 44 | ['name' => 'Surgelé', 'parent' => 1], | ||
| 45 | ['name' => 'Frais', 'parent' => 1], | ||
| 46 | ['name' => 'Sec', 'parent' => 1], | ||
| 47 | ['name' => 'Boissons', 'parent' => 1], | ||
| 48 | ['name' => 'Fruits&Légumes', 'parent' => 3], | ||
| 49 | ['name' => 'Patisseries', 'parent' => 3], | ||
| 50 | ['name' => 'Viandes', 'parent' => 3], | ||
| 51 | ['name' => 'Fruits&Légumes', 'parent' => 4], | ||
| 52 | ['name' => 'Patisseries', 'parent' => 4], | ||
| 53 | ['name' => 'Viandes', 'parent' => 4], | ||
| 54 | ['name' => 'Fruits&Légumes', 'parent' => 5], | ||
| 55 | ['name' => 'Patisseries', 'parent' => 5], | ||
| 56 | ['name' => 'Bières', 'parent' => 6], | ||
| 57 | ['name' => 'Vins', 'parent' => 6], | ||
| 58 | ]; | ||
| 59 |         foreach ($familyArray as $key => $family) { | ||
| 60 | $familyLog = new FamilyLog(); | ||
| 61 | $familyLog->setName($family['name']); | ||
| 62 |             if (isset($family['parent'])) { | ||
| 63 | $parent = $familyLogs[$family['parent'] - 1]; | ||
|  | |||
| 64 | $familyLog->setParent($parent); | ||
| 65 | } | ||
| 66 | $familyLogs[$key] = $familyLog; | ||
| 67 | |||
| 68 | $manager->persist($familyLog); | ||
| 69 | |||
| 70 | $order = $key + 1; | ||
| 71 |             $this->addReference('family-log'.$order, $familyLog); | ||
| 72 | } | ||
| 73 | |||
| 74 | // Load ZoneStorage | ||
| 75 | $zoneArray = [ | ||
| 76 | ['name' => 'Chambre négative'], | ||
| 77 | ['name' => 'Chambre posistive'], | ||
| 78 | ['name' => 'Réserve sèche'], | ||
| 79 | ['name' => 'Réserve boissons'], | ||
| 80 | ['name' => 'Armoire à boissons'], | ||
| 81 | ['name' => 'Caisse'], | ||
| 82 | ]; | ||
| 83 |         foreach ($zoneArray as $key => $zone) { | ||
| 84 | $zoneStorage = new ZoneStorage(); | ||
| 85 | $zoneStorage->setName($zone['name']); | ||
| 86 | |||
| 87 | $manager->persist($zoneStorage); | ||
| 88 | |||
| 89 | $order = $key + 1; | ||
| 90 |             $this->addReference('zoneStorage'.$order, $zoneStorage); | ||
| 91 | } | ||
| 92 | |||
| 93 | // Load Unit | ||
| 94 | $unitArray = [ | ||
| 95 | ['name' => 'Boite', 'abbr' => 'BOI'], | ||
| 96 | ['name' => 'Bouteille', 'abbr' => 'BTE'], | ||
| 97 | ['name' => 'Carton', 'abbr' => 'CAR'], | ||
| 98 | ['name' => 'Colis', 'abbr' => 'CLS'], | ||
| 99 | ['name' => 'Kilogramme', 'abbr' => 'KG'], | ||
| 100 | ['name' => 'Litre', 'abbr' => 'L'], | ||
| 101 | ['name' => 'Pièce', 'abbr' => 'PIE'], | ||
| 102 | ]; | ||
| 103 |         foreach ($unitArray as $key => $unit) { | ||
| 104 | $unitStorage = new Unit(); | ||
| 105 | $unitStorage->setName($unit['name']) | ||
| 106 | ->setAbbr($unit['abbr']); | ||
| 107 | |||
| 108 | $manager->persist($unitStorage); | ||
| 109 | |||
| 110 | $order = $key + 1; | ||
| 111 |             $this->addReference('unit'.$order, $unitStorage); | ||
| 112 | } | ||
| 113 | |||
| 114 | // Load Tva | ||
| 115 | $tvaArray = [ | ||
| 116 | ['rate' => '0.055'], | ||
| 117 | ['rate' => '0.1'], | ||
| 118 | ['rate' => '0.2'], | ||
| 119 | ]; | ||
| 120 |         foreach ($tvaArray as $key => $tvaRate) { | ||
| 121 | $tva = new Tva(); | ||
| 122 | $tva->setRate($tvaRate['rate']); | ||
| 123 | |||
| 124 | $manager->persist($tva); | ||
| 125 | |||
| 126 | $order = $key + 1; | ||
| 127 |             $this->addReference('tva'.$order, $tva); | ||
| 128 | } | ||
| 129 | |||
| 130 | $manager->flush(); | ||
| 131 | } | ||
| 143 |