| Conditions | 2 |
| Paths | 2 |
| Total Lines | 79 |
| 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 |
||
| 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' => 't_shirts', |
||
| 100 | 'name' => 'T-Shirts', |
||
| 101 | 'children' => [ |
||
| 102 | [ |
||
| 103 | 'code' => 'mens_t_shirts', |
||
| 104 | 'name' => 'Men', |
||
| 105 | ], |
||
| 106 | [ |
||
| 107 | 'code' => 'womens_t_shirts', |
||
| 108 | 'name' => 'Women', |
||
| 109 | ], |
||
| 110 | ], |
||
| 111 | ], |
||
| 112 | ], |
||
| 113 | ]]]); |
||
| 114 | |||
| 115 | $this->productAttributeFixture->load(['custom' => [ |
||
| 116 | ['name' => 'T-Shirt brand', 'code' => 't_shirt_brand', 'type' => TextAttributeType::TYPE], |
||
| 117 | ['name' => 'T-Shirt collection', 'code' => 't_shirt_collection', 'type' => TextAttributeType::TYPE], |
||
| 118 | ['name' => 'T-Shirt material', 'code' => 't_shirt_material', 'type' => TextAttributeType::TYPE], |
||
| 119 | ]]); |
||
| 120 | |||
| 121 | $this->productOptionFixture->load(['custom' => [ |
||
| 122 | [ |
||
| 123 | 'name' => 'T-Shirt color', |
||
| 124 | 'code' => 't_shirt_color', |
||
| 125 | 'values' => [ |
||
| 126 | 't_shirt_color_red' => 'Red', |
||
| 127 | 't_shirt_color_black' => 'Black', |
||
| 128 | 't_shirt_color_white' => 'White', |
||
| 129 | ], |
||
| 130 | ], |
||
| 131 | [ |
||
| 132 | 'name' => 'T-Shirt size', |
||
| 133 | 'code' => 't_shirt_size', |
||
| 134 | 'values' => [ |
||
| 135 | 't_shirt_size_s' => 'S', |
||
| 136 | 't_shirt_size_m' => 'M', |
||
| 137 | 't_shirt_size_l' => 'L', |
||
| 138 | 't_shirt_size_xl' => 'XL', |
||
| 139 | 't_shirt_size_xxl' => 'XXL', |
||
| 140 | ], |
||
| 141 | ], |
||
| 142 | ]]); |
||
| 143 | |||
| 144 | $products = []; |
||
| 145 | $productsNames = $this->getUniqueNames($options['amount']); |
||
| 146 | for ($i = 0; $i < $options['amount']; ++$i) { |
||
| 147 | $categoryTaxonCode = $this->faker->randomElement(['mens_t_shirts', 'womens_t_shirts']); |
||
| 148 | |||
| 149 | $products[] = [ |
||
| 150 | 'name' => sprintf('T-Shirt "%s"', $productsNames[$i]), |
||
| 151 | 'code' => $this->faker->uuid, |
||
| 152 | 'main_taxon' => $categoryTaxonCode, |
||
| 153 | 'taxons' => [$categoryTaxonCode], |
||
| 154 | 'product_attributes' => [ |
||
| 155 | 't_shirt_brand' => $this->faker->randomElement(['Nike', 'Adidas', 'JKM-476 Streetwear', 'Potato', 'Centipede Wear']), |
||
| 156 | 't_shirt_collection' => sprintf('Sylius %s %s', $this->faker->randomElement(['Summer', 'Winter', 'Spring', 'Autumn']), mt_rand(1995, 2012)), |
||
| 157 | 't_shirt_material' => $this->faker->randomElement(['Centipede', 'Wool', 'Centipede 10% / Wool 90%', 'Potato 100%']), |
||
| 158 | ], |
||
| 159 | 'product_options' => ['t_shirt_color', 't_shirt_size'], |
||
| 160 | 'images' => [ |
||
| 161 | 'main' => sprintf('%s/../Resources/fixtures/%s', __DIR__, 't-shirts.jpg'), |
||
| 162 | 'thumbnail' => sprintf('%s/../Resources/fixtures/%s', __DIR__, 't-shirts.jpg'), |
||
| 163 | ], |
||
| 164 | ]; |
||
| 165 | } |
||
| 166 | |||
| 167 | $this->productFixture->load(['custom' => $products]); |
||
| 168 | } |
||
| 169 | |||
| 201 |
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.