| Conditions | 127 |
| Paths | > 20000 |
| Total Lines | 522 |
| Code Lines | 352 |
| 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 |
||
| 284 | protected function handleArguments(array $argv) |
||
| 285 | { |
||
| 286 | try { |
||
| 287 | $this->options = Getopt::getopt( |
||
| 288 | $argv, |
||
| 289 | 'd:c:hv', |
||
| 290 | \array_keys($this->longOptions) |
||
| 291 | ); |
||
| 292 | } catch (Exception $t) { |
||
| 293 | $this->showError($t->getMessage()); |
||
| 294 | } |
||
| 295 | |||
| 296 | foreach ($this->options[0] as $option) { |
||
| 297 | switch ($option[0]) { |
||
| 298 | case '--colors': |
||
| 299 | $this->arguments['colors'] = $option[1] ?: ResultPrinter::COLOR_AUTO; |
||
| 300 | break; |
||
| 301 | |||
| 302 | case '--bootstrap': |
||
| 303 | $this->arguments['bootstrap'] = $option[1]; |
||
| 304 | break; |
||
| 305 | |||
| 306 | case '--columns': |
||
| 307 | if (\is_numeric($option[1])) { |
||
| 308 | $this->arguments['columns'] = (int) $option[1]; |
||
| 309 | } elseif ($option[1] == 'max') { |
||
| 310 | $this->arguments['columns'] = 'max'; |
||
| 311 | } |
||
| 312 | break; |
||
| 313 | |||
| 314 | case 'c': |
||
| 315 | case '--configuration': |
||
| 316 | $this->arguments['configuration'] = $option[1]; |
||
| 317 | break; |
||
| 318 | |||
| 319 | case '--coverage-clover': |
||
| 320 | $this->arguments['coverageClover'] = $option[1]; |
||
| 321 | break; |
||
| 322 | |||
| 323 | case '--coverage-crap4j': |
||
| 324 | $this->arguments['coverageCrap4J'] = $option[1]; |
||
| 325 | break; |
||
| 326 | |||
| 327 | case '--coverage-html': |
||
| 328 | $this->arguments['coverageHtml'] = $option[1]; |
||
| 329 | break; |
||
| 330 | |||
| 331 | case '--coverage-php': |
||
| 332 | $this->arguments['coveragePHP'] = $option[1]; |
||
| 333 | break; |
||
| 334 | |||
| 335 | case '--coverage-text': |
||
| 336 | if ($option[1] === null) { |
||
| 337 | $option[1] = 'php://stdout'; |
||
| 338 | } |
||
| 339 | |||
| 340 | $this->arguments['coverageText'] = $option[1]; |
||
| 341 | $this->arguments['coverageTextShowUncoveredFiles'] = false; |
||
| 342 | $this->arguments['coverageTextShowOnlySummary'] = false; |
||
| 343 | break; |
||
| 344 | |||
| 345 | case '--coverage-xml': |
||
| 346 | $this->arguments['coverageXml'] = $option[1]; |
||
| 347 | break; |
||
| 348 | |||
| 349 | case 'd': |
||
| 350 | $ini = \explode('=', $option[1]); |
||
| 351 | |||
| 352 | if (isset($ini[0])) { |
||
| 353 | if (isset($ini[1])) { |
||
| 354 | \ini_set($ini[0], $ini[1]); |
||
| 355 | } else { |
||
| 356 | \ini_set($ini[0], true); |
||
| 357 | } |
||
| 358 | } |
||
| 359 | break; |
||
| 360 | |||
| 361 | case '--debug': |
||
| 362 | $this->arguments['debug'] = true; |
||
| 363 | break; |
||
| 364 | |||
| 365 | case 'h': |
||
| 366 | case '--help': |
||
| 367 | $this->showHelp(); |
||
| 368 | exit(TestRunner::SUCCESS_EXIT); |
||
| 369 | break; |
||
| 370 | |||
| 371 | case '--filter': |
||
| 372 | $this->arguments['filter'] = $option[1]; |
||
| 373 | break; |
||
| 374 | |||
| 375 | case '--testsuite': |
||
| 376 | $this->arguments['testsuite'] = $option[1]; |
||
| 377 | break; |
||
| 378 | |||
| 379 | case '--generate-configuration': |
||
| 380 | $this->printVersionString(); |
||
| 381 | |||
| 382 | \printf( |
||
| 383 | "Generating phpunit.xml in %s\n\n", |
||
| 384 | \getcwd() |
||
| 385 | ); |
||
| 386 | |||
| 387 | print 'Bootstrap script (relative to path shown above; default: vendor/autoload.php): '; |
||
| 388 | $bootstrapScript = \trim(\fgets(STDIN)); |
||
| 389 | |||
| 390 | print 'Tests directory (relative to path shown above; default: tests): '; |
||
| 391 | $testsDirectory = \trim(\fgets(STDIN)); |
||
| 392 | |||
| 393 | print 'Source directory (relative to path shown above; default: src): '; |
||
| 394 | $src = \trim(\fgets(STDIN)); |
||
| 395 | |||
| 396 | if ($bootstrapScript == '') { |
||
| 397 | $bootstrapScript = 'vendor/autoload.php'; |
||
| 398 | } |
||
| 399 | |||
| 400 | if ($testsDirectory == '') { |
||
| 401 | $testsDirectory = 'tests'; |
||
| 402 | } |
||
| 403 | |||
| 404 | if ($src == '') { |
||
| 405 | $src = 'src'; |
||
| 406 | } |
||
| 407 | |||
| 408 | $generator = new ConfigurationGenerator; |
||
| 409 | |||
| 410 | \file_put_contents( |
||
| 411 | 'phpunit.xml', |
||
| 412 | $generator->generateDefaultConfiguration( |
||
| 413 | Version::series(), |
||
| 414 | $bootstrapScript, |
||
| 415 | $testsDirectory, |
||
| 416 | $src |
||
| 417 | ) |
||
| 418 | ); |
||
| 419 | |||
| 420 | \printf( |
||
| 421 | "\nGenerated phpunit.xml in %s\n", |
||
| 422 | \getcwd() |
||
| 423 | ); |
||
| 424 | |||
| 425 | exit(TestRunner::SUCCESS_EXIT); |
||
| 426 | break; |
||
| 427 | |||
| 428 | case '--group': |
||
| 429 | $this->arguments['groups'] = \explode(',', $option[1]); |
||
| 430 | break; |
||
| 431 | |||
| 432 | case '--exclude-group': |
||
| 433 | $this->arguments['excludeGroups'] = \explode( |
||
| 434 | ',', |
||
| 435 | $option[1] |
||
| 436 | ); |
||
| 437 | break; |
||
| 438 | |||
| 439 | case '--test-suffix': |
||
| 440 | $this->arguments['testSuffixes'] = \explode( |
||
| 441 | ',', |
||
| 442 | $option[1] |
||
| 443 | ); |
||
| 444 | break; |
||
| 445 | |||
| 446 | case '--include-path': |
||
| 447 | $includePath = $option[1]; |
||
| 448 | break; |
||
| 449 | |||
| 450 | case '--list-groups': |
||
| 451 | $this->arguments['listGroups'] = true; |
||
| 452 | break; |
||
| 453 | |||
| 454 | case '--list-suites': |
||
| 455 | $this->arguments['listSuites'] = true; |
||
| 456 | break; |
||
| 457 | |||
| 458 | case '--printer': |
||
| 459 | $this->arguments['printer'] = $option[1]; |
||
| 460 | break; |
||
| 461 | |||
| 462 | case '--loader': |
||
| 463 | $this->arguments['loader'] = $option[1]; |
||
| 464 | break; |
||
| 465 | |||
| 466 | case '--log-junit': |
||
| 467 | $this->arguments['junitLogfile'] = $option[1]; |
||
| 468 | break; |
||
| 469 | |||
| 470 | case '--log-teamcity': |
||
| 471 | $this->arguments['teamcityLogfile'] = $option[1]; |
||
| 472 | break; |
||
| 473 | |||
| 474 | case '--process-isolation': |
||
| 475 | $this->arguments['processIsolation'] = true; |
||
| 476 | break; |
||
| 477 | |||
| 478 | case '--repeat': |
||
| 479 | $this->arguments['repeat'] = (int) $option[1]; |
||
| 480 | break; |
||
| 481 | |||
| 482 | case '--stderr': |
||
| 483 | $this->arguments['stderr'] = true; |
||
| 484 | break; |
||
| 485 | |||
| 486 | case '--stop-on-error': |
||
| 487 | $this->arguments['stopOnError'] = true; |
||
| 488 | break; |
||
| 489 | |||
| 490 | case '--stop-on-failure': |
||
| 491 | $this->arguments['stopOnFailure'] = true; |
||
| 492 | break; |
||
| 493 | |||
| 494 | case '--stop-on-warning': |
||
| 495 | $this->arguments['stopOnWarning'] = true; |
||
| 496 | break; |
||
| 497 | |||
| 498 | case '--stop-on-incomplete': |
||
| 499 | $this->arguments['stopOnIncomplete'] = true; |
||
| 500 | break; |
||
| 501 | |||
| 502 | case '--stop-on-risky': |
||
| 503 | $this->arguments['stopOnRisky'] = true; |
||
| 504 | break; |
||
| 505 | |||
| 506 | case '--stop-on-skipped': |
||
| 507 | $this->arguments['stopOnSkipped'] = true; |
||
| 508 | break; |
||
| 509 | |||
| 510 | case '--fail-on-warning': |
||
| 511 | $this->arguments['failOnWarning'] = true; |
||
| 512 | break; |
||
| 513 | |||
| 514 | case '--fail-on-risky': |
||
| 515 | $this->arguments['failOnRisky'] = true; |
||
| 516 | break; |
||
| 517 | |||
| 518 | case '--teamcity': |
||
| 519 | $this->arguments['printer'] = TeamCity::class; |
||
| 520 | break; |
||
| 521 | |||
| 522 | case '--testdox': |
||
| 523 | $this->arguments['printer'] = TextResultPrinter::class; |
||
| 524 | break; |
||
| 525 | |||
| 526 | case '--testdox-group': |
||
| 527 | $this->arguments['testdoxGroups'] = \explode( |
||
| 528 | ',', |
||
| 529 | $option[1] |
||
| 530 | ); |
||
| 531 | break; |
||
| 532 | |||
| 533 | case '--testdox-exclude-group': |
||
| 534 | $this->arguments['testdoxExcludeGroups'] = \explode( |
||
| 535 | ',', |
||
| 536 | $option[1] |
||
| 537 | ); |
||
| 538 | break; |
||
| 539 | |||
| 540 | case '--testdox-html': |
||
| 541 | $this->arguments['testdoxHTMLFile'] = $option[1]; |
||
| 542 | break; |
||
| 543 | |||
| 544 | case '--testdox-text': |
||
| 545 | $this->arguments['testdoxTextFile'] = $option[1]; |
||
| 546 | break; |
||
| 547 | |||
| 548 | case '--testdox-xml': |
||
| 549 | $this->arguments['testdoxXMLFile'] = $option[1]; |
||
| 550 | break; |
||
| 551 | |||
| 552 | case '--no-configuration': |
||
| 553 | $this->arguments['useDefaultConfiguration'] = false; |
||
| 554 | break; |
||
| 555 | |||
| 556 | case '--no-extensions': |
||
| 557 | $this->arguments['noExtensions'] = true; |
||
| 558 | break; |
||
| 559 | |||
| 560 | case '--no-coverage': |
||
| 561 | $this->arguments['noCoverage'] = true; |
||
| 562 | break; |
||
| 563 | |||
| 564 | case '--globals-backup': |
||
| 565 | $this->arguments['backupGlobals'] = true; |
||
| 566 | break; |
||
| 567 | |||
| 568 | case '--static-backup': |
||
| 569 | $this->arguments['backupStaticAttributes'] = true; |
||
| 570 | break; |
||
| 571 | |||
| 572 | case 'v': |
||
| 573 | case '--verbose': |
||
| 574 | $this->arguments['verbose'] = true; |
||
| 575 | break; |
||
| 576 | |||
| 577 | case '--atleast-version': |
||
| 578 | if (\version_compare(Version::id(), $option[1], '>=')) { |
||
| 579 | exit(TestRunner::SUCCESS_EXIT); |
||
| 580 | } |
||
| 581 | |||
| 582 | exit(TestRunner::FAILURE_EXIT); |
||
| 583 | break; |
||
| 584 | |||
| 585 | case '--version': |
||
| 586 | $this->printVersionString(); |
||
| 587 | exit(TestRunner::SUCCESS_EXIT); |
||
| 588 | break; |
||
| 589 | |||
| 590 | case '--dont-report-useless-tests': |
||
| 591 | $this->arguments['reportUselessTests'] = false; |
||
| 592 | break; |
||
| 593 | |||
| 594 | case '--strict-coverage': |
||
| 595 | $this->arguments['strictCoverage'] = true; |
||
| 596 | break; |
||
| 597 | |||
| 598 | case '--disable-coverage-ignore': |
||
| 599 | $this->arguments['disableCodeCoverageIgnore'] = true; |
||
| 600 | break; |
||
| 601 | |||
| 602 | case '--strict-global-state': |
||
| 603 | $this->arguments['beStrictAboutChangesToGlobalState'] = true; |
||
| 604 | break; |
||
| 605 | |||
| 606 | case '--disallow-test-output': |
||
| 607 | $this->arguments['disallowTestOutput'] = true; |
||
| 608 | break; |
||
| 609 | |||
| 610 | case '--disallow-resource-usage': |
||
| 611 | $this->arguments['beStrictAboutResourceUsageDuringSmallTests'] = true; |
||
| 612 | break; |
||
| 613 | |||
| 614 | case '--enforce-time-limit': |
||
| 615 | $this->arguments['enforceTimeLimit'] = true; |
||
| 616 | break; |
||
| 617 | |||
| 618 | case '--disallow-todo-tests': |
||
| 619 | $this->arguments['disallowTodoAnnotatedTests'] = true; |
||
| 620 | break; |
||
| 621 | |||
| 622 | case '--reverse-list': |
||
| 623 | $this->arguments['reverseList'] = true; |
||
| 624 | break; |
||
| 625 | |||
| 626 | case '--check-version': |
||
| 627 | $this->handleVersionCheck(); |
||
| 628 | break; |
||
| 629 | |||
| 630 | case '--whitelist': |
||
| 631 | $this->arguments['whitelist'] = $option[1]; |
||
| 632 | break; |
||
| 633 | |||
| 634 | default: |
||
| 635 | $optionName = \str_replace('--', '', $option[0]); |
||
| 636 | |||
| 637 | $handler = null; |
||
| 638 | if (isset($this->longOptions[$optionName])) { |
||
| 639 | $handler = $this->longOptions[$optionName]; |
||
| 640 | } elseif (isset($this->longOptions[$optionName . '='])) { |
||
| 641 | $handler = $this->longOptions[$optionName . '=']; |
||
| 642 | } |
||
| 643 | |||
| 644 | if (isset($handler) && \is_callable([$this, $handler])) { |
||
| 645 | $this->$handler($option[1]); |
||
| 646 | } |
||
| 647 | } |
||
| 648 | } |
||
| 649 | |||
| 650 | $this->handleCustomTestSuite(); |
||
| 651 | |||
| 652 | if (!isset($this->arguments['test'])) { |
||
| 653 | if (isset($this->options[1][0])) { |
||
| 654 | $this->arguments['test'] = $this->options[1][0]; |
||
| 655 | } |
||
| 656 | |||
| 657 | if (isset($this->options[1][1])) { |
||
| 658 | $this->arguments['testFile'] = \realpath($this->options[1][1]); |
||
| 659 | } else { |
||
| 660 | $this->arguments['testFile'] = ''; |
||
| 661 | } |
||
| 662 | |||
| 663 | if (isset($this->arguments['test']) && |
||
| 664 | \is_file($this->arguments['test']) && |
||
| 665 | \substr($this->arguments['test'], -5, 5) != '.phpt') { |
||
| 666 | $this->arguments['testFile'] = \realpath($this->arguments['test']); |
||
| 667 | $this->arguments['test'] = \substr($this->arguments['test'], 0, \strrpos($this->arguments['test'], '.')); |
||
| 668 | } |
||
| 669 | } |
||
| 670 | |||
| 671 | if (!isset($this->arguments['testSuffixes'])) { |
||
| 672 | $this->arguments['testSuffixes'] = ['Test.php', '.phpt']; |
||
| 673 | } |
||
| 674 | |||
| 675 | if (isset($includePath)) { |
||
| 676 | \ini_set( |
||
| 677 | 'include_path', |
||
| 678 | $includePath . PATH_SEPARATOR . \ini_get('include_path') |
||
| 679 | ); |
||
| 680 | } |
||
| 681 | |||
| 682 | if ($this->arguments['loader'] !== null) { |
||
| 683 | $this->arguments['loader'] = $this->handleLoader($this->arguments['loader']); |
||
| 684 | } |
||
| 685 | |||
| 686 | if (isset($this->arguments['configuration']) && |
||
| 687 | \is_dir($this->arguments['configuration'])) { |
||
| 688 | $configurationFile = $this->arguments['configuration'] . '/phpunit.xml'; |
||
| 689 | |||
| 690 | if (\file_exists($configurationFile)) { |
||
| 691 | $this->arguments['configuration'] = \realpath( |
||
| 692 | $configurationFile |
||
| 693 | ); |
||
| 694 | } elseif (\file_exists($configurationFile . '.dist')) { |
||
| 695 | $this->arguments['configuration'] = \realpath( |
||
| 696 | $configurationFile . '.dist' |
||
| 697 | ); |
||
| 698 | } |
||
| 699 | } elseif (!isset($this->arguments['configuration']) && |
||
| 700 | $this->arguments['useDefaultConfiguration']) { |
||
| 701 | if (\file_exists('phpunit.xml')) { |
||
| 702 | $this->arguments['configuration'] = \realpath('phpunit.xml'); |
||
| 703 | } elseif (\file_exists('phpunit.xml.dist')) { |
||
| 704 | $this->arguments['configuration'] = \realpath( |
||
| 705 | 'phpunit.xml.dist' |
||
| 706 | ); |
||
| 707 | } |
||
| 708 | } |
||
| 709 | |||
| 710 | if (isset($this->arguments['configuration'])) { |
||
| 711 | try { |
||
| 712 | $configuration = Configuration::getInstance( |
||
| 713 | $this->arguments['configuration'] |
||
| 714 | ); |
||
| 715 | } catch (Throwable $t) { |
||
| 716 | print $t->getMessage() . "\n"; |
||
| 717 | exit(TestRunner::FAILURE_EXIT); |
||
| 718 | } |
||
| 719 | |||
| 720 | $phpunitConfiguration = $configuration->getPHPUnitConfiguration(); |
||
| 721 | |||
| 722 | $configuration->handlePHPConfiguration(); |
||
| 723 | |||
| 724 | /* |
||
| 725 | * Issue #1216 |
||
| 726 | */ |
||
| 727 | if (isset($this->arguments['bootstrap'])) { |
||
| 728 | $this->handleBootstrap($this->arguments['bootstrap']); |
||
| 729 | } elseif (isset($phpunitConfiguration['bootstrap'])) { |
||
| 730 | $this->handleBootstrap($phpunitConfiguration['bootstrap']); |
||
| 731 | } |
||
| 732 | |||
| 733 | /* |
||
| 734 | * Issue #657 |
||
| 735 | */ |
||
| 736 | if (isset($phpunitConfiguration['stderr']) && !isset($this->arguments['stderr'])) { |
||
| 737 | $this->arguments['stderr'] = $phpunitConfiguration['stderr']; |
||
| 738 | } |
||
| 739 | |||
| 740 | if (isset($phpunitConfiguration['extensionsDirectory']) && !isset($this->arguments['noExtensions']) && \extension_loaded('phar')) { |
||
| 741 | $this->handleExtensions($phpunitConfiguration['extensionsDirectory']); |
||
| 742 | } |
||
| 743 | |||
| 744 | if (isset($phpunitConfiguration['columns']) && !isset($this->arguments['columns'])) { |
||
| 745 | $this->arguments['columns'] = $phpunitConfiguration['columns']; |
||
| 746 | } |
||
| 747 | |||
| 748 | if (!isset($this->arguments['printer']) && isset($phpunitConfiguration['printerClass'])) { |
||
| 749 | if (isset($phpunitConfiguration['printerFile'])) { |
||
| 750 | $file = $phpunitConfiguration['printerFile']; |
||
| 751 | } else { |
||
| 752 | $file = ''; |
||
| 753 | } |
||
| 754 | |||
| 755 | $this->arguments['printer'] = $this->handlePrinter( |
||
| 756 | $phpunitConfiguration['printerClass'], |
||
| 757 | $file |
||
| 758 | ); |
||
| 759 | } |
||
| 760 | |||
| 761 | if (isset($phpunitConfiguration['testSuiteLoaderClass'])) { |
||
| 762 | if (isset($phpunitConfiguration['testSuiteLoaderFile'])) { |
||
| 763 | $file = $phpunitConfiguration['testSuiteLoaderFile']; |
||
| 764 | } else { |
||
| 765 | $file = ''; |
||
| 766 | } |
||
| 767 | |||
| 768 | $this->arguments['loader'] = $this->handleLoader( |
||
| 769 | $phpunitConfiguration['testSuiteLoaderClass'], |
||
| 770 | $file |
||
| 771 | ); |
||
| 772 | } |
||
| 773 | |||
| 774 | if (!isset($this->arguments['testsuite']) && isset($phpunitConfiguration['defaultTestSuite'])) { |
||
| 775 | $this->arguments['testsuite'] = $phpunitConfiguration['defaultTestSuite']; |
||
| 776 | } |
||
| 777 | |||
| 778 | if (!isset($this->arguments['test'])) { |
||
| 779 | $testSuite = $configuration->getTestSuiteConfiguration($this->arguments['testsuite'] ?? null); |
||
| 780 | |||
| 781 | if ($testSuite !== null) { |
||
| 782 | $this->arguments['test'] = $testSuite; |
||
| 783 | } |
||
| 784 | } |
||
| 785 | } elseif (isset($this->arguments['bootstrap'])) { |
||
| 786 | $this->handleBootstrap($this->arguments['bootstrap']); |
||
| 787 | } |
||
| 788 | |||
| 789 | if (isset($this->arguments['printer']) && |
||
| 790 | \is_string($this->arguments['printer'])) { |
||
| 791 | $this->arguments['printer'] = $this->handlePrinter($this->arguments['printer']); |
||
| 792 | } |
||
| 793 | |||
| 794 | if (isset($this->arguments['test']) && \is_string($this->arguments['test']) && \substr($this->arguments['test'], -5, 5) == '.phpt') { |
||
| 795 | $test = new PhptTestCase($this->arguments['test']); |
||
| 796 | |||
| 797 | $this->arguments['test'] = new TestSuite; |
||
| 798 | $this->arguments['test']->addTest($test); |
||
| 799 | } |
||
| 800 | |||
| 801 | if (!isset($this->arguments['test'])) { |
||
| 802 | $this->showHelp(); |
||
| 803 | exit(TestRunner::EXCEPTION_EXIT); |
||
| 804 | } |
||
| 805 | } |
||
| 806 | |||
| 1107 |