Conditions | 4 |
Paths | 8 |
Total Lines | 54 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 2 |
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 |
||
108 | public function load(array $options) |
||
109 | { |
||
110 | $options = $this->optionsResolver->resolve($options); |
||
111 | |||
112 | $taxons = []; |
||
113 | if (null === $this->taxonRepository->findOneBy(['code' => 'CATEGORY'])) { |
||
114 | $taxons[] = ['name' => 'Category', 'code' => 'CATEGORY', 'parent' => null]; |
||
115 | } |
||
116 | |||
117 | if (null === $this->taxonRepository->findOneBy(['code' => 'BRAND'])) { |
||
118 | $taxons[] = ['name' => 'Brand', 'code' => 'BRAND', 'parent' => null]; |
||
119 | } |
||
120 | |||
121 | $this->taxonFixture->load(['custom' => array_merge($taxons, [ |
||
122 | ['name' => 'Books', 'code' => 'BOOKS', 'parent' => 'CATEGORY'], |
||
123 | ['name' => 'BookMania', 'code' => 'BOOKMANIA', 'parent' => 'BRAND'], |
||
124 | ])]); |
||
125 | |||
126 | $this->productAttributeFixture->load(['custom' => [ |
||
127 | ['name' => 'Book author', 'code' => 'BOOK-AUTHOR', 'type' => TextAttributeType::TYPE], |
||
128 | ['name' => 'Book ISBN', 'code' => 'BOOK-ISBN', 'type' => TextAttributeType::TYPE], |
||
129 | ['name' => 'Book pages', 'code' => 'BOOK-PAGES', 'type' => IntegerAttributeType::TYPE], |
||
130 | ]]); |
||
131 | |||
132 | $this->productArchetypeFixture->load(['custom' => [ |
||
133 | [ |
||
134 | 'name' => 'Book', |
||
135 | 'code' => 'BOOK', |
||
136 | 'product_attributes' => ['BOOK-AUTHOR', 'BOOK-ISBN', 'BOOK-PAGES'], |
||
137 | 'product_options' => [], |
||
138 | ], |
||
139 | ]]); |
||
140 | |||
141 | $products = []; |
||
142 | for ($i = 0; $i < $options['amount']; ++$i) { |
||
143 | $name = $this->faker->name; |
||
144 | |||
145 | $products[] = [ |
||
146 | 'name' => sprintf('Book "%s" by %s', $this->faker->word, $name), |
||
147 | 'code' => $this->faker->uuid, |
||
148 | 'main_taxon' => 'BOOKS', |
||
149 | 'product_archetype' => 'BOOK', |
||
150 | 'taxons' => ['BOOKS', 'BOOKMANIA'], |
||
151 | 'product_attributes' => [ |
||
152 | 'BOOK-AUTHOR' => $name, |
||
153 | 'BOOK-ISBN' => $this->faker->isbn13, |
||
154 | 'BOOK-PAGES' => $this->faker->numberBetween(42, 1024), |
||
155 | ], |
||
156 | 'images' => [sprintf('%s/../Resources/fixtures/%s', __DIR__, 'books.jpg')], |
||
157 | ]; |
||
158 | } |
||
159 | |||
160 | $this->productFixture->load(['custom' => $products]); |
||
161 | } |
||
162 | |||
174 |