| Conditions | 116 |
| Paths | > 20000 |
| Total Lines | 334 |
| Code Lines | 194 |
| 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 |
||
| 734 | protected function handleConfiguration(array &$arguments) |
||
| 735 | { |
||
| 736 | if (isset($arguments['configuration']) && |
||
| 737 | !$arguments['configuration'] instanceof Configuration) { |
||
| 738 | $arguments['configuration'] = Configuration::getInstance( |
||
| 739 | $arguments['configuration'] |
||
| 740 | ); |
||
| 741 | } |
||
| 742 | |||
| 743 | $arguments['debug'] = $arguments['debug'] ?? false; |
||
| 744 | $arguments['filter'] = $arguments['filter'] ?? false; |
||
| 745 | $arguments['listeners'] = $arguments['listeners'] ?? []; |
||
| 746 | |||
| 747 | if (isset($arguments['configuration'])) { |
||
| 748 | $arguments['configuration']->handlePHPConfiguration(); |
||
| 749 | |||
| 750 | $phpunitConfiguration = $arguments['configuration']->getPHPUnitConfiguration(); |
||
| 751 | |||
| 752 | if (isset($phpunitConfiguration['backupGlobals']) && !isset($arguments['backupGlobals'])) { |
||
| 753 | $arguments['backupGlobals'] = $phpunitConfiguration['backupGlobals']; |
||
| 754 | } |
||
| 755 | |||
| 756 | if (isset($phpunitConfiguration['backupStaticAttributes']) && !isset($arguments['backupStaticAttributes'])) { |
||
| 757 | $arguments['backupStaticAttributes'] = $phpunitConfiguration['backupStaticAttributes']; |
||
| 758 | } |
||
| 759 | |||
| 760 | if (isset($phpunitConfiguration['beStrictAboutChangesToGlobalState']) && !isset($arguments['beStrictAboutChangesToGlobalState'])) { |
||
| 761 | $arguments['beStrictAboutChangesToGlobalState'] = $phpunitConfiguration['beStrictAboutChangesToGlobalState']; |
||
| 762 | } |
||
| 763 | |||
| 764 | if (isset($phpunitConfiguration['bootstrap']) && !isset($arguments['bootstrap'])) { |
||
| 765 | $arguments['bootstrap'] = $phpunitConfiguration['bootstrap']; |
||
| 766 | } |
||
| 767 | |||
| 768 | if (isset($phpunitConfiguration['cacheTokens']) && !isset($arguments['cacheTokens'])) { |
||
| 769 | $arguments['cacheTokens'] = $phpunitConfiguration['cacheTokens']; |
||
| 770 | } |
||
| 771 | |||
| 772 | if (isset($phpunitConfiguration['colors']) && !isset($arguments['colors'])) { |
||
| 773 | $arguments['colors'] = $phpunitConfiguration['colors']; |
||
| 774 | } |
||
| 775 | |||
| 776 | if (isset($phpunitConfiguration['convertErrorsToExceptions']) && !isset($arguments['convertErrorsToExceptions'])) { |
||
| 777 | $arguments['convertErrorsToExceptions'] = $phpunitConfiguration['convertErrorsToExceptions']; |
||
| 778 | } |
||
| 779 | |||
| 780 | if (isset($phpunitConfiguration['convertNoticesToExceptions']) && !isset($arguments['convertNoticesToExceptions'])) { |
||
| 781 | $arguments['convertNoticesToExceptions'] = $phpunitConfiguration['convertNoticesToExceptions']; |
||
| 782 | } |
||
| 783 | |||
| 784 | if (isset($phpunitConfiguration['convertWarningsToExceptions']) && !isset($arguments['convertWarningsToExceptions'])) { |
||
| 785 | $arguments['convertWarningsToExceptions'] = $phpunitConfiguration['convertWarningsToExceptions']; |
||
| 786 | } |
||
| 787 | |||
| 788 | if (isset($phpunitConfiguration['processIsolation']) && !isset($arguments['processIsolation'])) { |
||
| 789 | $arguments['processIsolation'] = $phpunitConfiguration['processIsolation']; |
||
| 790 | } |
||
| 791 | |||
| 792 | if (isset($phpunitConfiguration['stopOnError']) && !isset($arguments['stopOnError'])) { |
||
| 793 | $arguments['stopOnError'] = $phpunitConfiguration['stopOnError']; |
||
| 794 | } |
||
| 795 | |||
| 796 | if (isset($phpunitConfiguration['stopOnFailure']) && !isset($arguments['stopOnFailure'])) { |
||
| 797 | $arguments['stopOnFailure'] = $phpunitConfiguration['stopOnFailure']; |
||
| 798 | } |
||
| 799 | |||
| 800 | if (isset($phpunitConfiguration['stopOnWarning']) && !isset($arguments['stopOnWarning'])) { |
||
| 801 | $arguments['stopOnWarning'] = $phpunitConfiguration['stopOnWarning']; |
||
| 802 | } |
||
| 803 | |||
| 804 | if (isset($phpunitConfiguration['stopOnIncomplete']) && !isset($arguments['stopOnIncomplete'])) { |
||
| 805 | $arguments['stopOnIncomplete'] = $phpunitConfiguration['stopOnIncomplete']; |
||
| 806 | } |
||
| 807 | |||
| 808 | if (isset($phpunitConfiguration['stopOnRisky']) && !isset($arguments['stopOnRisky'])) { |
||
| 809 | $arguments['stopOnRisky'] = $phpunitConfiguration['stopOnRisky']; |
||
| 810 | } |
||
| 811 | |||
| 812 | if (isset($phpunitConfiguration['stopOnSkipped']) && !isset($arguments['stopOnSkipped'])) { |
||
| 813 | $arguments['stopOnSkipped'] = $phpunitConfiguration['stopOnSkipped']; |
||
| 814 | } |
||
| 815 | |||
| 816 | if (isset($phpunitConfiguration['failOnWarning']) && !isset($arguments['failOnWarning'])) { |
||
| 817 | $arguments['failOnWarning'] = $phpunitConfiguration['failOnWarning']; |
||
| 818 | } |
||
| 819 | |||
| 820 | if (isset($phpunitConfiguration['failOnRisky']) && !isset($arguments['failOnRisky'])) { |
||
| 821 | $arguments['failOnRisky'] = $phpunitConfiguration['failOnRisky']; |
||
| 822 | } |
||
| 823 | |||
| 824 | if (isset($phpunitConfiguration['timeoutForSmallTests']) && !isset($arguments['timeoutForSmallTests'])) { |
||
| 825 | $arguments['timeoutForSmallTests'] = $phpunitConfiguration['timeoutForSmallTests']; |
||
| 826 | } |
||
| 827 | |||
| 828 | if (isset($phpunitConfiguration['timeoutForMediumTests']) && !isset($arguments['timeoutForMediumTests'])) { |
||
| 829 | $arguments['timeoutForMediumTests'] = $phpunitConfiguration['timeoutForMediumTests']; |
||
| 830 | } |
||
| 831 | |||
| 832 | if (isset($phpunitConfiguration['timeoutForLargeTests']) && !isset($arguments['timeoutForLargeTests'])) { |
||
| 833 | $arguments['timeoutForLargeTests'] = $phpunitConfiguration['timeoutForLargeTests']; |
||
| 834 | } |
||
| 835 | |||
| 836 | if (isset($phpunitConfiguration['reportUselessTests']) && !isset($arguments['reportUselessTests'])) { |
||
| 837 | $arguments['reportUselessTests'] = $phpunitConfiguration['reportUselessTests']; |
||
| 838 | } |
||
| 839 | |||
| 840 | if (isset($phpunitConfiguration['strictCoverage']) && !isset($arguments['strictCoverage'])) { |
||
| 841 | $arguments['strictCoverage'] = $phpunitConfiguration['strictCoverage']; |
||
| 842 | } |
||
| 843 | |||
| 844 | if (isset($phpunitConfiguration['ignoreDeprecatedCodeUnitsFromCodeCoverage']) && !isset($arguments['ignoreDeprecatedCodeUnitsFromCodeCoverage'])) { |
||
| 845 | $arguments['ignoreDeprecatedCodeUnitsFromCodeCoverage'] = $phpunitConfiguration['ignoreDeprecatedCodeUnitsFromCodeCoverage']; |
||
| 846 | } |
||
| 847 | |||
| 848 | if (isset($phpunitConfiguration['disallowTestOutput']) && !isset($arguments['disallowTestOutput'])) { |
||
| 849 | $arguments['disallowTestOutput'] = $phpunitConfiguration['disallowTestOutput']; |
||
| 850 | } |
||
| 851 | |||
| 852 | if (isset($phpunitConfiguration['enforceTimeLimit']) && !isset($arguments['enforceTimeLimit'])) { |
||
| 853 | $arguments['enforceTimeLimit'] = $phpunitConfiguration['enforceTimeLimit']; |
||
| 854 | } |
||
| 855 | |||
| 856 | if (isset($phpunitConfiguration['disallowTodoAnnotatedTests']) && !isset($arguments['disallowTodoAnnotatedTests'])) { |
||
| 857 | $arguments['disallowTodoAnnotatedTests'] = $phpunitConfiguration['disallowTodoAnnotatedTests']; |
||
| 858 | } |
||
| 859 | |||
| 860 | if (isset($phpunitConfiguration['beStrictAboutResourceUsageDuringSmallTests']) && !isset($arguments['beStrictAboutResourceUsageDuringSmallTests'])) { |
||
| 861 | $arguments['beStrictAboutResourceUsageDuringSmallTests'] = $phpunitConfiguration['beStrictAboutResourceUsageDuringSmallTests']; |
||
| 862 | } |
||
| 863 | |||
| 864 | if (isset($phpunitConfiguration['verbose']) && !isset($arguments['verbose'])) { |
||
| 865 | $arguments['verbose'] = $phpunitConfiguration['verbose']; |
||
| 866 | } |
||
| 867 | |||
| 868 | if (isset($phpunitConfiguration['reverseDefectList']) && !isset($arguments['reverseList'])) { |
||
| 869 | $arguments['reverseList'] = $phpunitConfiguration['reverseDefectList']; |
||
| 870 | } |
||
| 871 | |||
| 872 | if (isset($phpunitConfiguration['forceCoversAnnotation']) && !isset($arguments['forceCoversAnnotation'])) { |
||
| 873 | $arguments['forceCoversAnnotation'] = $phpunitConfiguration['forceCoversAnnotation']; |
||
| 874 | } |
||
| 875 | |||
| 876 | if (isset($phpunitConfiguration['disableCodeCoverageIgnore']) && !isset($arguments['disableCodeCoverageIgnore'])) { |
||
| 877 | $arguments['disableCodeCoverageIgnore'] = $phpunitConfiguration['disableCodeCoverageIgnore']; |
||
| 878 | } |
||
| 879 | |||
| 880 | if (isset($phpunitConfiguration['registerMockObjectsFromTestArgumentsRecursively']) && !isset($arguments['registerMockObjectsFromTestArgumentsRecursively'])) { |
||
| 881 | $arguments['registerMockObjectsFromTestArgumentsRecursively'] = $phpunitConfiguration['registerMockObjectsFromTestArgumentsRecursively']; |
||
| 882 | } |
||
| 883 | |||
| 884 | $groupCliArgs = []; |
||
| 885 | |||
| 886 | if (!empty($arguments['groups'])) { |
||
| 887 | $groupCliArgs = $arguments['groups']; |
||
| 888 | } |
||
| 889 | |||
| 890 | $groupConfiguration = $arguments['configuration']->getGroupConfiguration(); |
||
| 891 | |||
| 892 | if (!empty($groupConfiguration['include']) && !isset($arguments['groups'])) { |
||
| 893 | $arguments['groups'] = $groupConfiguration['include']; |
||
| 894 | } |
||
| 895 | |||
| 896 | if (!empty($groupConfiguration['exclude']) && !isset($arguments['excludeGroups'])) { |
||
| 897 | $arguments['excludeGroups'] = \array_diff($groupConfiguration['exclude'], $groupCliArgs); |
||
| 898 | } |
||
| 899 | |||
| 900 | foreach ($arguments['configuration']->getListenerConfiguration() as $listener) { |
||
| 901 | if (!\class_exists($listener['class'], false) && |
||
| 902 | $listener['file'] !== '') { |
||
| 903 | require_once $listener['file']; |
||
| 904 | } |
||
| 905 | |||
| 906 | if (!\class_exists($listener['class'])) { |
||
| 907 | throw new Exception( |
||
| 908 | \sprintf( |
||
| 909 | 'Class "%s" does not exist', |
||
| 910 | $listener['class'] |
||
| 911 | ) |
||
| 912 | ); |
||
| 913 | } |
||
| 914 | |||
| 915 | $listenerClass = new ReflectionClass($listener['class']); |
||
| 916 | |||
| 917 | if (!$listenerClass->implementsInterface(TestListener::class)) { |
||
| 918 | throw new Exception( |
||
| 919 | \sprintf( |
||
| 920 | 'Class "%s" does not implement the PHPUnit\Framework\TestListener interface', |
||
| 921 | $listener['class'] |
||
| 922 | ) |
||
| 923 | ); |
||
| 924 | } |
||
| 925 | |||
| 926 | if (\count($listener['arguments']) == 0) { |
||
| 927 | $listener = new $listener['class']; |
||
| 928 | } else { |
||
| 929 | $listener = $listenerClass->newInstanceArgs( |
||
| 930 | $listener['arguments'] |
||
| 931 | ); |
||
| 932 | } |
||
| 933 | |||
| 934 | $arguments['listeners'][] = $listener; |
||
| 935 | } |
||
| 936 | |||
| 937 | $loggingConfiguration = $arguments['configuration']->getLoggingConfiguration(); |
||
| 938 | |||
| 939 | if (isset($loggingConfiguration['coverage-clover']) && !isset($arguments['coverageClover'])) { |
||
| 940 | $arguments['coverageClover'] = $loggingConfiguration['coverage-clover']; |
||
| 941 | } |
||
| 942 | |||
| 943 | if (isset($loggingConfiguration['coverage-crap4j']) && !isset($arguments['coverageCrap4J'])) { |
||
| 944 | $arguments['coverageCrap4J'] = $loggingConfiguration['coverage-crap4j']; |
||
| 945 | |||
| 946 | if (isset($loggingConfiguration['crap4jThreshold']) && !isset($arguments['crap4jThreshold'])) { |
||
| 947 | $arguments['crap4jThreshold'] = $loggingConfiguration['crap4jThreshold']; |
||
| 948 | } |
||
| 949 | } |
||
| 950 | |||
| 951 | if (isset($loggingConfiguration['coverage-html']) && !isset($arguments['coverageHtml'])) { |
||
| 952 | if (isset($loggingConfiguration['lowUpperBound']) && !isset($arguments['reportLowUpperBound'])) { |
||
| 953 | $arguments['reportLowUpperBound'] = $loggingConfiguration['lowUpperBound']; |
||
| 954 | } |
||
| 955 | |||
| 956 | if (isset($loggingConfiguration['highLowerBound']) && !isset($arguments['reportHighLowerBound'])) { |
||
| 957 | $arguments['reportHighLowerBound'] = $loggingConfiguration['highLowerBound']; |
||
| 958 | } |
||
| 959 | |||
| 960 | $arguments['coverageHtml'] = $loggingConfiguration['coverage-html']; |
||
| 961 | } |
||
| 962 | |||
| 963 | if (isset($loggingConfiguration['coverage-php']) && !isset($arguments['coveragePHP'])) { |
||
| 964 | $arguments['coveragePHP'] = $loggingConfiguration['coverage-php']; |
||
| 965 | } |
||
| 966 | |||
| 967 | if (isset($loggingConfiguration['coverage-text']) && !isset($arguments['coverageText'])) { |
||
| 968 | $arguments['coverageText'] = $loggingConfiguration['coverage-text']; |
||
| 969 | |||
| 970 | if (isset($loggingConfiguration['coverageTextShowUncoveredFiles'])) { |
||
| 971 | $arguments['coverageTextShowUncoveredFiles'] = $loggingConfiguration['coverageTextShowUncoveredFiles']; |
||
| 972 | } else { |
||
| 973 | $arguments['coverageTextShowUncoveredFiles'] = false; |
||
| 974 | } |
||
| 975 | |||
| 976 | if (isset($loggingConfiguration['coverageTextShowOnlySummary'])) { |
||
| 977 | $arguments['coverageTextShowOnlySummary'] = $loggingConfiguration['coverageTextShowOnlySummary']; |
||
| 978 | } else { |
||
| 979 | $arguments['coverageTextShowOnlySummary'] = false; |
||
| 980 | } |
||
| 981 | } |
||
| 982 | |||
| 983 | if (isset($loggingConfiguration['coverage-xml']) && !isset($arguments['coverageXml'])) { |
||
| 984 | $arguments['coverageXml'] = $loggingConfiguration['coverage-xml']; |
||
| 985 | } |
||
| 986 | |||
| 987 | if (isset($loggingConfiguration['plain'])) { |
||
| 988 | $arguments['listeners'][] = new ResultPrinter( |
||
| 989 | $loggingConfiguration['plain'], |
||
| 990 | true |
||
| 991 | ); |
||
| 992 | } |
||
| 993 | |||
| 994 | if (isset($loggingConfiguration['teamcity']) && !isset($arguments['teamcityLogfile'])) { |
||
| 995 | $arguments['teamcityLogfile'] = $loggingConfiguration['teamcity']; |
||
| 996 | } |
||
| 997 | |||
| 998 | if (isset($loggingConfiguration['junit']) && !isset($arguments['junitLogfile'])) { |
||
| 999 | $arguments['junitLogfile'] = $loggingConfiguration['junit']; |
||
| 1000 | } |
||
| 1001 | |||
| 1002 | if (isset($loggingConfiguration['testdox-html']) && !isset($arguments['testdoxHTMLFile'])) { |
||
| 1003 | $arguments['testdoxHTMLFile'] = $loggingConfiguration['testdox-html']; |
||
| 1004 | } |
||
| 1005 | |||
| 1006 | if (isset($loggingConfiguration['testdox-text']) && !isset($arguments['testdoxTextFile'])) { |
||
| 1007 | $arguments['testdoxTextFile'] = $loggingConfiguration['testdox-text']; |
||
| 1008 | } |
||
| 1009 | |||
| 1010 | if (isset($loggingConfiguration['testdox-xml']) && !isset($arguments['testdoxXMLFile'])) { |
||
| 1011 | $arguments['testdoxXMLFile'] = $loggingConfiguration['testdox-xml']; |
||
| 1012 | } |
||
| 1013 | |||
| 1014 | $testdoxGroupConfiguration = $arguments['configuration']->getTestdoxGroupConfiguration(); |
||
| 1015 | |||
| 1016 | if (isset($testdoxGroupConfiguration['include']) && |
||
| 1017 | !isset($arguments['testdoxGroups'])) { |
||
| 1018 | $arguments['testdoxGroups'] = $testdoxGroupConfiguration['include']; |
||
| 1019 | } |
||
| 1020 | |||
| 1021 | if (isset($testdoxGroupConfiguration['exclude']) && |
||
| 1022 | !isset($arguments['testdoxExcludeGroups'])) { |
||
| 1023 | $arguments['testdoxExcludeGroups'] = $testdoxGroupConfiguration['exclude']; |
||
| 1024 | } |
||
| 1025 | } |
||
| 1026 | |||
| 1027 | $arguments['addUncoveredFilesFromWhitelist'] = $arguments['addUncoveredFilesFromWhitelist'] ?? true; |
||
| 1028 | $arguments['backupGlobals'] = $arguments['backupGlobals'] ?? null; |
||
| 1029 | $arguments['backupStaticAttributes'] = $arguments['backupStaticAttributes'] ?? null; |
||
| 1030 | $arguments['beStrictAboutChangesToGlobalState'] = $arguments['beStrictAboutChangesToGlobalState'] ?? null; |
||
| 1031 | $arguments['beStrictAboutResourceUsageDuringSmallTests'] = $arguments['beStrictAboutResourceUsageDuringSmallTests'] ?? false; |
||
| 1032 | $arguments['cacheTokens'] = $arguments['cacheTokens'] ?? false; |
||
| 1033 | $arguments['colors'] = $arguments['colors'] ?? ResultPrinter::COLOR_DEFAULT; |
||
| 1034 | $arguments['columns'] = $arguments['columns'] ?? 80; |
||
| 1035 | $arguments['convertErrorsToExceptions'] = $arguments['convertErrorsToExceptions'] ?? true; |
||
| 1036 | $arguments['convertNoticesToExceptions'] = $arguments['convertNoticesToExceptions'] ?? true; |
||
| 1037 | $arguments['convertWarningsToExceptions'] = $arguments['convertWarningsToExceptions'] ?? true; |
||
| 1038 | $arguments['crap4jThreshold'] = $arguments['crap4jThreshold'] ?? 30; |
||
| 1039 | $arguments['disallowTestOutput'] = $arguments['disallowTestOutput'] ?? false; |
||
| 1040 | $arguments['disallowTodoAnnotatedTests'] = $arguments['disallowTodoAnnotatedTests'] ?? false; |
||
| 1041 | $arguments['enforceTimeLimit'] = $arguments['enforceTimeLimit'] ?? false; |
||
| 1042 | $arguments['excludeGroups'] = $arguments['excludeGroups'] ?? []; |
||
| 1043 | $arguments['failOnRisky'] = $arguments['failOnRisky'] ?? false; |
||
| 1044 | $arguments['failOnWarning'] = $arguments['failOnWarning'] ?? false; |
||
| 1045 | $arguments['groups'] = $arguments['groups'] ?? []; |
||
| 1046 | $arguments['processIsolation'] = $arguments['processIsolation'] ?? false; |
||
| 1047 | $arguments['processUncoveredFilesFromWhitelist'] = $arguments['processUncoveredFilesFromWhitelist'] ?? false; |
||
| 1048 | $arguments['registerMockObjectsFromTestArgumentsRecursively'] = $arguments['registerMockObjectsFromTestArgumentsRecursively'] ?? false; |
||
| 1049 | $arguments['repeat'] = $arguments['repeat'] ?? false; |
||
| 1050 | $arguments['reportHighLowerBound'] = $arguments['reportHighLowerBound'] ?? 90; |
||
| 1051 | $arguments['reportLowUpperBound'] = $arguments['reportLowUpperBound'] ?? 50; |
||
| 1052 | $arguments['reportUselessTests'] = $arguments['reportUselessTests'] ?? true; |
||
| 1053 | $arguments['reverseList'] = $arguments['reverseList'] ?? false; |
||
| 1054 | $arguments['stopOnError'] = $arguments['stopOnError'] ?? false; |
||
| 1055 | $arguments['stopOnFailure'] = $arguments['stopOnFailure'] ?? false; |
||
| 1056 | $arguments['stopOnIncomplete'] = $arguments['stopOnIncomplete'] ?? false; |
||
| 1057 | $arguments['stopOnRisky'] = $arguments['stopOnRisky'] ?? false; |
||
| 1058 | $arguments['stopOnSkipped'] = $arguments['stopOnSkipped'] ?? false; |
||
| 1059 | $arguments['stopOnWarning'] = $arguments['stopOnWarning'] ?? false; |
||
| 1060 | $arguments['strictCoverage'] = $arguments['strictCoverage'] ?? false; |
||
| 1061 | $arguments['testdoxExcludeGroups'] = $arguments['testdoxExcludeGroups'] ?? []; |
||
| 1062 | $arguments['testdoxGroups'] = $arguments['testdoxGroups'] ?? []; |
||
| 1063 | $arguments['timeoutForLargeTests'] = $arguments['timeoutForLargeTests'] ?? 60; |
||
| 1064 | $arguments['timeoutForMediumTests'] = $arguments['timeoutForMediumTests'] ?? 10; |
||
| 1065 | $arguments['timeoutForSmallTests'] = $arguments['timeoutForSmallTests'] ?? 1; |
||
| 1066 | $arguments['verbose'] = $arguments['verbose'] ?? false; |
||
| 1067 | } |
||
| 1068 | |||
| 1090 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.