Conditions | 10 |
Paths | 35 |
Total Lines | 95 |
Code Lines | 58 |
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 |
||
192 | public function createCloud($type, InputInterface $input) |
||
193 | { |
||
194 | if (!in_array($type, array('from-url', 'from-file'))) { |
||
195 | throw new \InvalidArgumentException('Invalid type for createCloud: ' . $type); |
||
196 | } |
||
197 | |||
198 | // Build the filters |
||
199 | $filtersBuilder = $this->getFilterBuilder( |
||
200 | $input->getOption('min-word-length'), |
||
201 | $input->getOption('max-word-length'), |
||
202 | $input->getOption('case'), |
||
203 | $input->getOption('no-remove-numbers'), |
||
204 | $input->getOption('no-remove-unwanted'), |
||
205 | $input->getOption('no-remove-trailing') |
||
206 | ); |
||
207 | |||
208 | // Create a placer |
||
209 | $placerName = $this->getPlacer($input->getOption('placer')); |
||
210 | $placer = PlacerFactory::getInstance()->getPlacer( |
||
211 | $placerName, |
||
212 | $input->getOption('width'), |
||
213 | $input->getOption('height') |
||
214 | ); |
||
215 | |||
216 | // Get the font file |
||
217 | $fontsPath = $input->getOption('fonts-path') |
||
218 | ? realpath($input->getOption('fonts-path')) |
||
219 | : constant('BASE_PATH') . '/fonts' |
||
220 | ; |
||
221 | $factory = FontsFactory::create($fontsPath); |
||
222 | $font = $this->getFont($factory, $input->getOption('font')); |
||
223 | |||
224 | // Create the list builder |
||
225 | $listBuilder = WordsListBuilder::create() |
||
226 | ->setMaxWords($input->getOption('max-word-count')) |
||
227 | ->setFilters($filtersBuilder->build()) |
||
228 | ->randomizeOrientation($input->getOption('vertical-probability')) |
||
229 | ; |
||
230 | |||
231 | if ($type === 'from-file') { |
||
232 | $file = $input->getArgument('file'); |
||
233 | if (!file_exists($file)) { |
||
234 | throw new \InvalidArgumentException('File not found: ' . $file); |
||
235 | } |
||
236 | $listBuilder->importWords(file_get_contents($file)); |
||
237 | } else { |
||
238 | $listBuilder->importUrl($input->getArgument('url')); |
||
239 | } |
||
240 | |||
241 | $sortBy = $input->getOption('sort-by'); |
||
242 | $sortOrder = $input->getOption('sort-order'); |
||
243 | |||
244 | if ($sortBy && $sortOrder) { |
||
245 | $listBuilder->sort($sortBy, $sortOrder); |
||
246 | } |
||
247 | |||
248 | // Apply a color generator if needed |
||
249 | $colorGenerator = $this->getColorGenerator( |
||
250 | $input->getOption('palette'), |
||
251 | $input->getOption('palette-type'), |
||
252 | $input->getOption('palettes-file') |
||
253 | ); |
||
254 | |||
255 | if ($colorGenerator) { |
||
256 | $listBuilder->randomizeColors($colorGenerator); |
||
257 | } |
||
258 | |||
259 | // Build the list |
||
260 | $list = $listBuilder->build('list'); |
||
261 | |||
262 | // Create a cloud builder |
||
263 | $cloudBuilder = CloudBuilder::create($factory) |
||
264 | ->setBackgroundColor($input->getOption('background-color')) |
||
265 | ->setDimension($input->getOption('width'), $input->getOption('height')) |
||
266 | ->setFont($font) |
||
267 | ->setFontSizes($input->getOption('min-font-size'), $input->getOption('max-font-size')) |
||
268 | ->setPlacer($placerName) |
||
269 | ->setSizeGenerator($this->getFontSizeGenerator($input->getOption('font-size-boost'))) |
||
270 | ->useList($list) |
||
271 | ; |
||
272 | |||
273 | if ($input->getOption('precise')) { |
||
274 | $cloudBuilder->setPrecise(); |
||
275 | } |
||
276 | |||
277 | // Render the cloud and show the bounding boxes and the usher if needed |
||
278 | $image = $this->render( |
||
279 | $cloudBuilder, |
||
280 | $factory, |
||
281 | $input->getOption('render-usher') ? $placer : null, |
||
282 | $input->getOption('render-boxes') |
||
283 | ); |
||
284 | |||
285 | $this->output($image, $input->getOption('format'), $input->getOption('save-to-file')); |
||
286 | } |
||
287 | } |
||
288 |
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: