| Conditions | 5 |
| Paths | 8 |
| Total Lines | 87 |
| 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 |
||
| 235 | public function createCloud($type, InputInterface $input) |
||
| 236 | { |
||
| 237 | Assert::oneOf($type, array('from-url', 'from-file'), 'Invalid type for createCloud: ' . $type); |
||
| 238 | |||
| 239 | $stopwatch = new Stopwatch(); |
||
| 240 | $stopwatch->start('createCloud'); |
||
| 241 | |||
| 242 | // Build the filters |
||
| 243 | $filtersBuilder = $this->getFilterBuilder( |
||
| 244 | $input->getOption('min-word-length'), |
||
| 245 | $input->getOption('max-word-length'), |
||
| 246 | $input->getOption('case'), |
||
| 247 | $input->getOption('no-remove-numbers'), |
||
| 248 | $input->getOption('no-remove-unwanted'), |
||
| 249 | $input->getOption('no-remove-trailing') |
||
| 250 | ); |
||
| 251 | |||
| 252 | // Create a placer |
||
| 253 | $placerName = $this->getPlacer($input->getOption('placer')); |
||
| 254 | $placer = PlacerFactory::getInstance()->getPlacer( |
||
| 255 | $placerName, |
||
| 256 | $input->getOption('width'), |
||
| 257 | $input->getOption('height') |
||
| 258 | ); |
||
| 259 | |||
| 260 | // Get the font file |
||
| 261 | $fontsPath = $input->getOption('fonts-path') |
||
| 262 | ? realpath($input->getOption('fonts-path')) |
||
| 263 | : constant('BASE_PATH') . '/fonts' |
||
| 264 | ; |
||
| 265 | $factory = FontsFactory::create($fontsPath); |
||
| 266 | $font = $this->getFont($factory, $input->getOption('font')); |
||
| 267 | |||
| 268 | // Create the list builder |
||
| 269 | $listBuilder = WordsListBuilder::create() |
||
| 270 | ->setMaxWords($input->getOption('max-word-count')) |
||
| 271 | ->setFilters($filtersBuilder->build()) |
||
| 272 | ->randomizeOrientation($input->getOption('vertical-probability')) |
||
| 273 | ; |
||
| 274 | |||
| 275 | $this->insertWords($listBuilder, $type, $input->getOption('save-to-file'), $input->getArgument('url')); |
||
| 276 | |||
| 277 | $this->sortWords($listBuilder, $input->getOption('sort-by'), $input->getOption('sort-order')); |
||
| 278 | |||
| 279 | // Apply a color generator if needed |
||
| 280 | $colorGenerator = $this->getColorGenerator( |
||
| 281 | $input->getOption('palette'), |
||
| 282 | $input->getOption('palette-type'), |
||
| 283 | $input->getOption('palettes-file') |
||
| 284 | ); |
||
| 285 | |||
| 286 | if ($colorGenerator) { |
||
| 287 | $listBuilder->randomizeColors($colorGenerator); |
||
| 288 | } |
||
| 289 | |||
| 290 | // Build the list |
||
| 291 | $list = $listBuilder->build('list'); |
||
| 292 | |||
| 293 | // Create a cloud builder |
||
| 294 | $cloudBuilder = CloudBuilder::create($factory) |
||
| 295 | ->setBackgroundColor($input->getOption('background-color')) |
||
| 296 | ->setDimension($input->getOption('width'), $input->getOption('height')) |
||
| 297 | ->setFont($font) |
||
| 298 | ->setFontSizes($input->getOption('min-font-size'), $input->getOption('max-font-size')) |
||
| 299 | ->setPlacer($placerName) |
||
| 300 | ->setSizeGenerator($this->getFontSizeGenerator($input->getOption('font-size-boost'))) |
||
| 301 | ->useList($list) |
||
| 302 | ; |
||
| 303 | |||
| 304 | if ($input->getOption('precise')) { |
||
| 305 | $cloudBuilder->setPrecise(); |
||
| 306 | } |
||
| 307 | |||
| 308 | // Render the cloud and show the bounding boxes and the usher if needed |
||
| 309 | $image = $this->render( |
||
| 310 | $cloudBuilder, |
||
| 311 | $factory, |
||
| 312 | $input->getOption('render-usher') ? $placer : null, |
||
| 313 | $input->getOption('render-boxes'), |
||
| 314 | $input->getOption('render-mask') |
||
| 315 | ); |
||
| 316 | |||
| 317 | $this->output($image, $input->getOption('format'), $input->getOption('save-to-file')); |
||
| 318 | |||
| 319 | $event = $stopwatch->stop('createCloud'); |
||
| 320 | return $event; |
||
| 321 | } |
||
| 322 | } |
||
| 323 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: