| Conditions | 8 |
| Paths | 2 |
| Total Lines | 147 |
| Code Lines | 114 |
| 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 |
||
| 261 | private function configureOptions(OptionsResolver $resolver) |
||
| 262 | { |
||
| 263 | $options = [ |
||
| 264 | // General options |
||
| 265 | 'ignore-errors' => 'bool', |
||
| 266 | 'abort-on-error' => 'bool', |
||
| 267 | 'default-search' => 'string', |
||
| 268 | 'force-generic-extractor' => 'bool', |
||
| 269 | // Network options |
||
| 270 | 'proxy' => 'string', |
||
| 271 | 'socket-timeout' => 'int', |
||
| 272 | 'source-address' => 'string', |
||
| 273 | 'force-ipv4' => 'bool', |
||
| 274 | 'force-ipv6' => 'bool', |
||
| 275 | // Video selection options |
||
| 276 | 'match-title' => 'string', |
||
| 277 | 'reject-title' => 'string', |
||
| 278 | 'max-downloads' => 'int', |
||
| 279 | 'min-filesize' => 'string', |
||
| 280 | 'max-filesize' => 'string', |
||
| 281 | 'date' => 'string', |
||
| 282 | 'datebefore' => 'string', |
||
| 283 | 'dateafter' => 'string', |
||
| 284 | 'min-views' => 'int', |
||
| 285 | 'max-views' => 'int', |
||
| 286 | 'match-filter' => 'string', |
||
| 287 | 'download-archive' => 'string', |
||
| 288 | 'include-ads' => 'bool', |
||
| 289 | // Download Options |
||
| 290 | 'rate-limit' => 'string', |
||
| 291 | 'retries' => 'int|string', |
||
| 292 | 'buffer-size' => 'string', |
||
| 293 | 'no-resize-buffer' => 'bool', |
||
| 294 | 'xattr-set-filesize' => 'bool', |
||
| 295 | 'hls-prefer-native' => 'bool', |
||
| 296 | 'external-downloader' => 'string', |
||
| 297 | 'external-downloader-args' => 'string', |
||
| 298 | // Filesystem Options |
||
| 299 | 'batch-file' => 'string', |
||
| 300 | 'output' => 'string', |
||
| 301 | 'autonumber-size' => 'int', |
||
| 302 | 'restrict-filenames' => 'bool', |
||
| 303 | 'no-overwrites' => 'bool', |
||
| 304 | 'continue' => 'bool', |
||
| 305 | 'no-continue' => 'bool', |
||
| 306 | 'no-part' => 'bool', |
||
| 307 | 'no-mtime' => 'bool', |
||
| 308 | 'write-description' => 'bool', |
||
| 309 | 'write-annotations' => 'bool', |
||
| 310 | 'cookies' => 'string', |
||
| 311 | 'cache-dir' => 'string', |
||
| 312 | 'no-cache-dir' => 'bool', |
||
| 313 | 'rm-cache-dir' => 'bool', |
||
| 314 | 'id' => 'bool', |
||
| 315 | // Thumbnail images |
||
| 316 | 'write-thumbnail' => 'bool', |
||
| 317 | 'write-all-thumbnails' => 'bool', |
||
| 318 | // Verbosity / Simulation Options |
||
| 319 | 'quiet' => 'bool', |
||
| 320 | 'no-warnings' => 'bool', |
||
| 321 | 'simulate' => 'bool', |
||
| 322 | 'skip-download' => 'bool', |
||
| 323 | 'call-home' => 'bool', |
||
| 324 | 'no-call-home' => 'bool', |
||
| 325 | // Workarounds |
||
| 326 | 'encoding' => 'string', |
||
| 327 | 'no-check-certificate' => 'bool', |
||
| 328 | 'prefer-insecure' => 'bool', |
||
| 329 | 'user-agent' => 'string', |
||
| 330 | 'referer' => 'string', |
||
| 331 | 'add-header' => 'array', |
||
| 332 | 'bidi-workaround' => 'bool', |
||
| 333 | 'sleep-interval' => 'int', |
||
| 334 | // Video Format Options |
||
| 335 | 'format' => 'string', |
||
| 336 | 'prefer-free-formats' => 'bool', |
||
| 337 | 'max-quality' => 'string', |
||
| 338 | 'youtube-skip-dash-manifest' => 'bool', |
||
| 339 | 'merge-output-format' => 'string', |
||
| 340 | // Subtitle Options |
||
| 341 | 'write-sub' => 'bool', |
||
| 342 | 'write-auto-sub' => 'bool', |
||
| 343 | 'all-subs' => 'bool', |
||
| 344 | 'sub-format' => 'string', |
||
| 345 | 'sub-lang' => 'string', |
||
| 346 | // Authentication Options |
||
| 347 | 'username' => 'string', |
||
| 348 | 'password' => 'string', |
||
| 349 | 'twofactor' => 'string', |
||
| 350 | 'netrc' => 'bool', |
||
| 351 | 'video-password' => 'string', |
||
| 352 | // Post-processing Options |
||
| 353 | 'extract-audio' => 'bool', |
||
| 354 | 'audio-format' => 'string', |
||
| 355 | 'audio-quality' => 'int', |
||
| 356 | 'recode-video' => 'string', |
||
| 357 | 'keep-video' => 'bool', |
||
| 358 | 'no-post-overwrites' => 'bool', |
||
| 359 | 'embed-subs' => 'bool', |
||
| 360 | 'embed-thumbnail' => 'bool', |
||
| 361 | 'add-metadata' => 'bool', |
||
| 362 | 'metadata-from-title' => 'string', |
||
| 363 | 'xattrs' => 'bool', |
||
| 364 | 'fixup' => 'string', |
||
| 365 | 'prefer-avconv' => 'bool', |
||
| 366 | 'prefer-ffmpeg' => 'bool', |
||
| 367 | 'ffmpeg-location' => 'string', |
||
| 368 | 'exec' => 'string', |
||
| 369 | 'convert-subtitles' => 'string', |
||
| 370 | ]; |
||
| 371 | |||
| 372 | $resolver->setDefined(array_keys($options)); |
||
| 373 | |||
| 374 | foreach ($options as $option => $types) { |
||
| 375 | $resolver->setAllowedTypes($option, explode('|', $types)); |
||
| 376 | } |
||
| 377 | |||
| 378 | $resolver->setAllowedValues('retries', function ($value) { |
||
| 379 | if (is_string($value) && 'infinite' != $value) { |
||
| 380 | return false; |
||
| 381 | } |
||
| 382 | |||
| 383 | return true; |
||
| 384 | }); |
||
| 385 | |||
| 386 | $resolver->setAllowedValues('external-downloader', ['aria2c', 'avconv', 'axel', 'curl', 'ffmpeg', 'httpie', 'wget']); |
||
| 387 | |||
| 388 | $resolver->setAllowedValues('audio-format', $this->allowedAudioFormats); |
||
| 389 | |||
| 390 | $resolver->setAllowedValues('ffmpeg-location', function ($value) { |
||
| 391 | if (!is_file($value) && !is_dir($value)) { |
||
| 392 | return false; |
||
| 393 | } |
||
| 394 | |||
| 395 | return true; |
||
| 396 | }); |
||
| 397 | |||
| 398 | $resolver->setNormalizer('add-header', function (Options $options, $value) { |
||
| 399 | foreach ($value as $k => $v) { |
||
| 400 | if (false === strpos($v, ':')) { |
||
| 401 | unset($value[$k]); |
||
| 402 | } |
||
| 403 | } |
||
| 404 | |||
| 405 | return $value; |
||
| 406 | }); |
||
| 407 | } |
||
| 408 | |||
| 420 |
If you suppress an error, we recommend checking for the error condition explicitly: