Conditions | 14 |
Paths | 456 |
Total Lines | 124 |
Code Lines | 72 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
80 | public function load(array $options): void |
||
81 | { |
||
82 | $options = $this->optionsResolver->resolve($options); |
||
83 | |||
84 | /** @var TaxonInterface $taxonBanners */ |
||
85 | $taxonBanners = $this->taxonFactory->createNew(); |
||
86 | $taxonBanners->setCode('banners'); |
||
87 | foreach ($this->getLocales() as $localeCode) { |
||
88 | $taxonBanners->setCurrentLocale($localeCode); |
||
89 | $taxonBanners->setFallbackLocale($localeCode); |
||
90 | |||
91 | $taxonBanners->setName('Banners'); |
||
92 | $taxonBanners->setSlug('banners'); |
||
93 | $taxonBanners->setDescription($this->faker->text); |
||
94 | } |
||
95 | |||
96 | /** @var TaxonInterface $taxonHome */ |
||
97 | $taxonHome = $this->taxonFactory->createNew(); |
||
98 | $taxonHome->setCode('home'); |
||
99 | $taxonHome->setParent($taxonBanners); |
||
100 | foreach ($this->getLocales() as $localeCode) { |
||
101 | $taxonHome->setCurrentLocale($localeCode); |
||
102 | $taxonHome->setFallbackLocale($localeCode); |
||
103 | |||
104 | $taxonHome->setName('Home'); |
||
105 | $taxonHome->setSlug('banners/home'); |
||
106 | $taxonHome->setDescription($this->faker->text); |
||
107 | } |
||
108 | |||
109 | $this->objectManager->persist($taxonBanners); |
||
110 | $this->objectManager->persist($taxonHome); |
||
111 | |||
112 | $channels = $this->channelRepository->findAll(); |
||
113 | |||
114 | /** @var ChannelInterface $channel */ |
||
115 | foreach ($channels as $channel) { |
||
116 | /** @var BannerInterface $banner */ |
||
117 | $banner = $this->bannerFactory->createNew(); |
||
118 | |||
119 | $banner->setCode($this->faker->slug); |
||
120 | $banner->addChannel($channel); |
||
121 | $banner->addTaxon($taxonHome); |
||
122 | |||
123 | foreach ($this->getLocales() as $localeCode) { |
||
124 | $banner->setCurrentLocale($localeCode); |
||
125 | $banner->setFallbackLocale($localeCode); |
||
126 | |||
127 | $banner->setUrl($this->faker->url); |
||
128 | |||
129 | $imageFinder = new Finder(); |
||
130 | |||
131 | $imagesPath = __DIR__ . '/../Resources/fixtures/banner/images'; |
||
132 | $mobileImagesPath = __DIR__ . '/../Resources/fixtures/banner/mobile-images'; |
||
133 | |||
134 | foreach ($imageFinder->files()->in($imagesPath)->name('01.png') as $img) { |
||
135 | /** @var string $path */ |
||
136 | $path = $img->getRealPath(); |
||
137 | /** @var string $filename */ |
||
138 | $filename = $img->getFilename(); |
||
139 | $file = new UploadedFile($path, $filename); |
||
140 | $banner->setImageFile($file); |
||
141 | } |
||
142 | |||
143 | foreach ($imageFinder->files()->in($mobileImagesPath)->name('01.png') as $img) { |
||
144 | /** @var string $path */ |
||
145 | $path = $img->getRealPath(); |
||
146 | /** @var string $filename */ |
||
147 | $filename = $img->getFilename(); |
||
148 | $file = new UploadedFile($path, $filename); |
||
149 | $banner->setMobileImageFile($file); |
||
150 | } |
||
151 | } |
||
152 | |||
153 | $this->objectManager->persist($banner); |
||
154 | } |
||
155 | |||
156 | /** @var ChannelInterface $channel */ |
||
157 | foreach ($channels as $channel) { |
||
158 | $imageIndex = 1; |
||
159 | $mobileImageIndex = 1; |
||
160 | for ($i=1; $i <= $options['banners_per_channel']; $i++) { |
||
161 | /** @var BannerInterface $banner */ |
||
162 | $banner = $this->bannerFactory->createNew(); |
||
163 | |||
164 | $banner->setCode($this->faker->slug); |
||
165 | $banner->addChannel($channel); |
||
166 | |||
167 | foreach ($this->getLocales() as $localeCode) { |
||
168 | $banner->setCurrentLocale($localeCode); |
||
169 | $banner->setFallbackLocale($localeCode); |
||
170 | |||
171 | $banner->setUrl($this->faker->url); |
||
172 | |||
173 | $imageFinder = new Finder(); |
||
174 | |||
175 | $imagesPath = __DIR__ . '/../Resources/fixtures/banner/images'; |
||
176 | $mobileImagesPath = __DIR__ . '/../Resources/fixtures/banner/mobile-images'; |
||
177 | |||
178 | foreach ($imageFinder->files()->in($imagesPath)->name('0'.$imageIndex.'.png') as $img) { |
||
179 | /** @var string $path */ |
||
180 | $path = $img->getRealPath(); |
||
181 | /** @var string $filename */ |
||
182 | $filename = $img->getFilename(); |
||
183 | $file = new UploadedFile($path, $filename); |
||
184 | $banner->setImageFile($file); |
||
185 | } |
||
186 | $imageIndex = $imageIndex>=4?1:$imageIndex+1; |
||
187 | |||
188 | foreach ($imageFinder->files()->in($mobileImagesPath)->name('0'.$mobileImageIndex.'.png') as $img) { |
||
189 | /** @var string $path */ |
||
190 | $path = $img->getRealPath(); |
||
191 | /** @var string $filename */ |
||
192 | $filename = $img->getFilename(); |
||
193 | $file = new UploadedFile($path, $filename); |
||
194 | $banner->setMobileImageFile($file); |
||
195 | } |
||
196 | $mobileImageIndex = $mobileImageIndex>=4?1:$mobileImageIndex+1; |
||
197 | } |
||
198 | |||
199 | $this->objectManager->persist($banner); |
||
200 | } |
||
201 | } |
||
202 | |||
203 | $this->objectManager->flush(); |
||
204 | } |
||
237 |