| Conditions | 5 |
| Paths | 8 |
| Total Lines | 80 |
| Code Lines | 48 |
| 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 |
||
| 220 | public function createCloud($type, InputInterface $input) |
||
| 221 | { |
||
| 222 | Assert::oneOf($type, array('from-url', 'from-file'), 'Invalid type for createCloud: ' . $type); |
||
| 223 | |||
| 224 | // Build the filters |
||
| 225 | $filtersBuilder = $this->getFilterBuilder( |
||
| 226 | $input->getOption('min-word-length'), |
||
| 227 | $input->getOption('max-word-length'), |
||
| 228 | $input->getOption('case'), |
||
| 229 | $input->getOption('no-remove-numbers'), |
||
| 230 | $input->getOption('no-remove-unwanted'), |
||
| 231 | $input->getOption('no-remove-trailing') |
||
| 232 | ); |
||
| 233 | |||
| 234 | // Create a placer |
||
| 235 | $placerName = $this->getPlacer($input->getOption('placer')); |
||
| 236 | $placer = PlacerFactory::getInstance()->getPlacer( |
||
| 237 | $placerName, |
||
| 238 | $input->getOption('width'), |
||
| 239 | $input->getOption('height') |
||
| 240 | ); |
||
| 241 | |||
| 242 | // Get the font file |
||
| 243 | $fontsPath = $input->getOption('fonts-path') |
||
| 244 | ? realpath($input->getOption('fonts-path')) |
||
| 245 | : constant('BASE_PATH') . '/fonts' |
||
| 246 | ; |
||
| 247 | $factory = FontsFactory::create($fontsPath); |
||
| 248 | $font = $this->getFont($factory, $input->getOption('font')); |
||
| 249 | |||
| 250 | // Create the list builder |
||
| 251 | $listBuilder = WordsListBuilder::create() |
||
| 252 | ->setMaxWords($input->getOption('max-word-count')) |
||
| 253 | ->setFilters($filtersBuilder->build()) |
||
| 254 | ->randomizeOrientation($input->getOption('vertical-probability')) |
||
| 255 | ; |
||
| 256 | |||
| 257 | $this->insertWords($listBuilder, $type, $input->getArgument('file'), $input->getArgument('url')); |
||
| 258 | |||
| 259 | $this->sortWords($listBuilder, $input->getOption('sort-by'), $input->getOption('sort-order')); |
||
| 260 | |||
| 261 | // Apply a color generator if needed |
||
| 262 | $colorGenerator = $this->getColorGenerator( |
||
| 263 | $input->getOption('palette'), |
||
| 264 | $input->getOption('palette-type'), |
||
| 265 | $input->getOption('palettes-file') |
||
| 266 | ); |
||
| 267 | |||
| 268 | if ($colorGenerator) { |
||
| 269 | $listBuilder->randomizeColors($colorGenerator); |
||
| 270 | } |
||
| 271 | |||
| 272 | // Build the list |
||
| 273 | $list = $listBuilder->build('list'); |
||
| 274 | |||
| 275 | // Create a cloud builder |
||
| 276 | $cloudBuilder = CloudBuilder::create($factory) |
||
| 277 | ->setBackgroundColor($input->getOption('background-color')) |
||
| 278 | ->setDimension($input->getOption('width'), $input->getOption('height')) |
||
| 279 | ->setFont($font) |
||
| 280 | ->setFontSizes($input->getOption('min-font-size'), $input->getOption('max-font-size')) |
||
| 281 | ->setPlacer($placerName) |
||
| 282 | ->setSizeGenerator($this->getFontSizeGenerator($input->getOption('font-size-boost'))) |
||
| 283 | ->useList($list) |
||
| 284 | ; |
||
| 285 | |||
| 286 | if ($input->getOption('preLoggercise')) { |
||
| 287 | $cloudBuilder->setPrecise(); |
||
| 288 | } |
||
| 289 | |||
| 290 | // Render the cloud and show the bounding boxes and the usher if needed |
||
| 291 | $image = $this->render( |
||
| 292 | $cloudBuilder, |
||
| 293 | $factory, |
||
| 294 | $input->getOption('render-usher') ? $placer : null, |
||
| 295 | $input->getOption('render-boxes') |
||
| 296 | ); |
||
| 297 | |||
| 298 | $this->output($image, $input->getOption('format'), $input->getOption('save-to-file')); |
||
| 299 | } |
||
| 300 | } |
||
| 301 |
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: