Conditions | 6 |
Paths | 24 |
Total Lines | 99 |
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 | /** |
||
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']); |
||
|
|||
128 | |||
129 | $manager->persist($tva); |
||
130 | |||
131 | $order = $key + 1; |
||
132 | $this->addReference('tva'.$order, $tva); |
||
133 | } |
||
134 | |||
135 | $manager->flush(); |
||
136 | } |
||
137 | |||
143 |
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: