Conditions | 8 |
Paths | 32 |
Total Lines | 91 |
Code Lines | 56 |
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 |
||
179 | public function createCloud($type, InputInterface $input) |
||
180 | { |
||
181 | Assert::oneOf($type, array('from-url', 'from-file'), 'Invalid type for createCloud: ' . $type); |
||
182 | |||
183 | // Build the filters |
||
184 | $filtersBuilder = $this->getFilterBuilder( |
||
185 | $input->getOption('min-word-length'), |
||
186 | $input->getOption('max-word-length'), |
||
187 | $input->getOption('case'), |
||
188 | $input->getOption('no-remove-numbers'), |
||
189 | $input->getOption('no-remove-unwanted'), |
||
190 | $input->getOption('no-remove-trailing') |
||
191 | ); |
||
192 | |||
193 | // Create a placer |
||
194 | $placerName = $this->getPlacer($input->getOption('placer')); |
||
195 | $placer = PlacerFactory::getInstance()->getPlacer( |
||
196 | $placerName, |
||
197 | $input->getOption('width'), |
||
198 | $input->getOption('height') |
||
199 | ); |
||
200 | |||
201 | // Get the font file |
||
202 | $fontsPath = $input->getOption('fonts-path') |
||
203 | ? realpath($input->getOption('fonts-path')) |
||
204 | : constant('BASE_PATH') . '/fonts' |
||
205 | ; |
||
206 | $factory = FontsFactory::create($fontsPath); |
||
207 | $font = $this->getFont($factory, $input->getOption('font')); |
||
208 | |||
209 | // Create the list builder |
||
210 | $listBuilder = WordsListBuilder::create() |
||
211 | ->setMaxWords($input->getOption('max-word-count')) |
||
212 | ->setFilters($filtersBuilder->build()) |
||
213 | ->randomizeOrientation($input->getOption('vertical-probability')) |
||
214 | ; |
||
215 | |||
216 | if ($type === 'from-file') { |
||
217 | $file = $input->getArgument('file'); |
||
218 | Assert::fileExists($file, 'File not found: ' . $file); |
||
219 | $listBuilder->importWords(file_get_contents($file)); |
||
220 | } else { |
||
221 | $listBuilder->importUrl($input->getArgument('url')); |
||
222 | } |
||
223 | |||
224 | $sortBy = $input->getOption('sort-by'); |
||
225 | $sortOrder = $input->getOption('sort-order'); |
||
226 | |||
227 | if ($sortBy && $sortOrder) { |
||
228 | $listBuilder->sort($sortBy, $sortOrder); |
||
229 | } |
||
230 | |||
231 | // Apply a color generator if needed |
||
232 | $colorGenerator = $this->getColorGenerator( |
||
233 | $input->getOption('palette'), |
||
234 | $input->getOption('palette-type'), |
||
235 | $input->getOption('palettes-file') |
||
236 | ); |
||
237 | |||
238 | if ($colorGenerator) { |
||
239 | $listBuilder->randomizeColors($colorGenerator); |
||
240 | } |
||
241 | |||
242 | // Build the list |
||
243 | $list = $listBuilder->build('list'); |
||
244 | |||
245 | // Create a cloud builder |
||
246 | $cloudBuilder = CloudBuilder::create($factory) |
||
247 | ->setBackgroundColor($input->getOption('background-color')) |
||
248 | ->setDimension($input->getOption('width'), $input->getOption('height')) |
||
249 | ->setFont($font) |
||
250 | ->setFontSizes($input->getOption('min-font-size'), $input->getOption('max-font-size')) |
||
251 | ->setPlacer($placerName) |
||
252 | ->setSizeGenerator($this->getFontSizeGenerator($input->getOption('font-size-boost'))) |
||
253 | ->useList($list) |
||
254 | ; |
||
255 | |||
256 | if ($input->getOption('precise')) { |
||
257 | $cloudBuilder->setPrecise(); |
||
258 | } |
||
259 | |||
260 | // Render the cloud and show the bounding boxes and the usher if needed |
||
261 | $image = $this->render( |
||
262 | $cloudBuilder, |
||
263 | $factory, |
||
264 | $input->getOption('render-usher') ? $placer : null, |
||
265 | $input->getOption('render-boxes') |
||
266 | ); |
||
267 | |||
268 | $this->output($image, $input->getOption('format'), $input->getOption('save-to-file')); |
||
269 | } |
||
270 | } |
||
271 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: