Conditions | 16 |
Paths | 648 |
Total Lines | 45 |
Lines | 6 |
Ratio | 13.33 % |
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 |
||
88 | public function groupsForTest(\PHPUnit\Framework\Test $test) |
||
89 | { |
||
90 | $groups = []; |
||
91 | $filename = Descriptor::getTestFileName($test); |
||
|
|||
92 | if ($test instanceof TestInterface) { |
||
93 | $groups = $test->getMetadata()->getGroups(); |
||
94 | } |
||
95 | if ($test instanceof Reported) { |
||
96 | $info = $test->getReportFields(); |
||
97 | if (isset($info['class'])) { |
||
98 | $groups = array_merge($groups, \PHPUnit\Util\Test::getGroups($info['class'], $info['name'])); |
||
99 | } |
||
100 | $filename = str_replace(['\\\\', '//'], ['\\', '/'], $info['file']); |
||
101 | } |
||
102 | if ($test instanceof \PHPUnit\Framework\TestCase) { |
||
103 | $groups = array_merge($groups, \PHPUnit\Util\Test::getGroups(get_class($test), $test->getName(false))); |
||
104 | } |
||
105 | if ($test instanceof \PHPUnit\Framework\TestSuite\DataProvider) { |
||
106 | $firstTest = $test->testAt(0); |
||
107 | if ($firstTest != false && $firstTest instanceof TestInterface) { |
||
108 | $groups = array_merge($groups, $firstTest->getMetadata()->getGroups()); |
||
109 | $filename = Descriptor::getTestFileName($firstTest); |
||
110 | } |
||
111 | } |
||
112 | |||
113 | foreach ($this->testsInGroups as $group => $tests) { |
||
114 | foreach ($tests as $testPattern) { |
||
115 | if ($filename == $testPattern) { |
||
116 | $groups[] = $group; |
||
117 | } |
||
118 | View Code Duplication | if (strpos($filename . ':' . $test->getName(false), $testPattern) === 0) { |
|
119 | $groups[] = $group; |
||
120 | } |
||
121 | if ($test instanceof \PHPUnit\Framework\TestSuite\DataProvider) { |
||
122 | $firstTest = $test->testAt(0); |
||
123 | if ($firstTest != false && $firstTest instanceof TestInterface) { |
||
124 | View Code Duplication | if (strpos($filename . ':' . $firstTest->getName(false), $testPattern) === 0) { |
|
125 | $groups[] = $group; |
||
126 | } |
||
127 | } |
||
128 | } |
||
129 | } |
||
130 | } |
||
131 | return array_unique($groups); |
||
132 | } |
||
133 | } |
||
134 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: