Conditions | 2 |
Paths | 2 |
Total Lines | 56 |
Code Lines | 37 |
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 |
||
84 | public function load(array $options) |
||
85 | { |
||
86 | $options = $this->optionsResolver->resolve($options); |
||
87 | |||
88 | $this->taxonFixture->load(['custom' => [[ |
||
89 | 'code' => 'category', |
||
90 | 'name' => 'Category', |
||
91 | 'children' => [ |
||
92 | [ |
||
93 | 'code' => 'books', |
||
94 | 'name' => 'Books', |
||
95 | ] |
||
96 | ] |
||
97 | ]]]); |
||
98 | |||
99 | $bookGenres = ['Fiction', 'Romance', 'Thriller', 'Sports']; |
||
100 | $this->productAttributeFixture->load(['custom' => [ |
||
101 | ['name' => 'Book author', 'code' => 'book_author', 'type' => TextAttributeType::TYPE], |
||
102 | ['name' => 'Book ISBN', 'code' => 'book_isbn', 'type' => TextAttributeType::TYPE], |
||
103 | ['name' => 'Book pages', 'code' => 'book_pages', 'type' => IntegerAttributeType::TYPE], |
||
104 | [ |
||
105 | 'name' => 'Book genre', |
||
106 | 'code' => 'book_genre', |
||
107 | 'type' => SelectAttributeType::TYPE, |
||
108 | 'configuration' => [ |
||
109 | 'multiple' => true, |
||
110 | 'choices' => $bookGenres, |
||
111 | ] |
||
112 | ], |
||
113 | ]]); |
||
114 | |||
115 | $products = []; |
||
116 | $productsNames = $this->getUniqueNames($options['amount']); |
||
117 | for ($i = 0; $i < $options['amount']; ++$i) { |
||
118 | $authorName = $this->faker->name; |
||
119 | |||
120 | $products[] = [ |
||
121 | 'name' => sprintf('Book "%s" by %s', $productsNames[$i], $authorName), |
||
122 | 'code' => $this->faker->uuid, |
||
123 | 'main_taxon' => 'books', |
||
124 | 'taxons' => ['books'], |
||
125 | 'product_attributes' => [ |
||
126 | 'book_author' => $authorName, |
||
127 | 'book_isbn' => $this->faker->isbn13, |
||
128 | 'book_pages' => $this->faker->numberBetween(42, 1024), |
||
129 | 'book_genre' => array_keys($this->faker->randomElements($bookGenres, $this->faker->randomKey($bookGenres) + 1)), |
||
130 | ], |
||
131 | 'images' => [ |
||
132 | [sprintf('%s/../Resources/fixtures/%s', __DIR__, 'books.jpg'), 'main'], |
||
133 | [sprintf('%s/../Resources/fixtures/%s', __DIR__, 'books.jpg'), 'thumbnail'], |
||
134 | ], |
||
135 | ]; |
||
136 | } |
||
137 | |||
138 | $this->productFixture->load(['custom' => $products]); |
||
139 | } |
||
140 | |||
172 |