| Conditions | 2 |
| Paths | 2 |
| Total Lines | 52 |
| Code Lines | 32 |
| 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 |
||
| 90 | public function load(array $options) |
||
| 91 | { |
||
| 92 | $options = $this->optionsResolver->resolve($options); |
||
| 93 | |||
| 94 | $this->taxonFixture->load(['custom' => [[ |
||
| 95 | 'code' => 'category', |
||
| 96 | 'name' => 'Category', |
||
| 97 | 'children' => [ |
||
| 98 | [ |
||
| 99 | 'code' => 'mugs', |
||
| 100 | 'name' => 'Mugs', |
||
| 101 | ] |
||
| 102 | ] |
||
| 103 | ]]]); |
||
| 104 | |||
| 105 | $this->productAttributeFixture->load(['custom' => [ |
||
| 106 | ['name' => 'Mug material', 'code' => 'mug_material', 'type' => TextAttributeType::TYPE], |
||
| 107 | ]]); |
||
| 108 | |||
| 109 | $this->productOptionFixture->load(['custom' => [ |
||
| 110 | [ |
||
| 111 | 'name' => 'Mug type', |
||
| 112 | 'code' => 'mug_type', |
||
| 113 | 'values' => [ |
||
| 114 | 'mug_type_medium' => 'Medium mug', |
||
| 115 | 'mug_type_double' => 'Double mug', |
||
| 116 | 'mug_type_monster' => 'Monster mug', |
||
| 117 | ], |
||
| 118 | ], |
||
| 119 | ]]); |
||
| 120 | |||
| 121 | $products = []; |
||
| 122 | $productsNames = $this->getUniqueNames($options['amount']); |
||
| 123 | for ($i = 0; $i < $options['amount']; ++$i) { |
||
| 124 | $products[] = [ |
||
| 125 | 'name' => sprintf('Mug "%s"', $productsNames[$i]), |
||
| 126 | 'code' => $this->faker->uuid, |
||
| 127 | 'main_taxon' => 'mugs', |
||
| 128 | 'taxons' => ['mugs'], |
||
| 129 | 'product_attributes' => [ |
||
| 130 | 'mug_material' => $this->faker->randomElement(['Invisible porcelain', 'Banana skin', 'Porcelain', 'Centipede']), |
||
| 131 | ], |
||
| 132 | 'product_options' => ['mug_type'], |
||
| 133 | 'images' => [ |
||
| 134 | 'main' => sprintf('%s/../Resources/fixtures/%s', __DIR__, 'mugs.jpg'), |
||
| 135 | 'thumbnail' => sprintf('%s/../Resources/fixtures/%s', __DIR__, 'mugs.jpg'), |
||
| 136 | ], |
||
| 137 | ]; |
||
| 138 | } |
||
| 139 | |||
| 140 | $this->productFixture->load(['custom' => $products]); |
||
| 141 | } |
||
| 142 | |||
| 174 |
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.