| Conditions | 2 |
| Paths | 1 |
| Total Lines | 63 |
| Code Lines | 47 |
| 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 |
||
| 78 | public function testArguments(): void |
||
| 79 | { |
||
| 80 | $this->markTestSkipped('Should be fixed'); |
||
| 81 | |||
| 82 | $dh = opendir(__DIR__); |
||
| 83 | $fh = tmpfile(); |
||
| 84 | |||
| 85 | $incomplete = unserialize('O:14:"BogusTestClass":0:{}'); |
||
| 86 | |||
| 87 | $exception = $this->createException([ |
||
| 88 | (object)['foo' => 1], |
||
| 89 | new \RuntimeException('test'), |
||
| 90 | $incomplete, |
||
| 91 | $dh, |
||
| 92 | $fh, |
||
| 93 | function () { |
||
| 94 | }, |
||
| 95 | [1, 2], |
||
| 96 | ['foo' => 123], |
||
| 97 | null, |
||
| 98 | true, |
||
| 99 | false, |
||
| 100 | 0, |
||
| 101 | 0.0, |
||
| 102 | '0', |
||
| 103 | '', |
||
| 104 | INF, |
||
| 105 | NAN, |
||
| 106 | ]); |
||
| 107 | |||
| 108 | $flattened = new FlattenException($exception); |
||
| 109 | $trace = $flattened->getTrace(); |
||
| 110 | $args = $trace[0]['args']; |
||
| 111 | $array = $args[0][1]; |
||
| 112 | |||
| 113 | closedir($dh); |
||
| 114 | fclose($fh); |
||
| 115 | |||
| 116 | $i = 0; |
||
| 117 | $this->assertSame(['object', 'stdClass'], $array[$i++]); |
||
| 118 | $this->assertSame(['object', \RuntimeException::class], $array[$i++]); |
||
| 119 | $this->assertSame(['incomplete-object', 'BogusTestClass'], $array[$i++]); |
||
| 120 | $this->assertSame(['resource', 'stream'], $array[$i++]); |
||
| 121 | $this->assertSame(['resource', 'stream'], $array[$i++]); |
||
| 122 | |||
| 123 | $args = $array[$i++]; |
||
| 124 | $this->assertSame($args[0], 'object'); |
||
| 125 | $this->assertTrue(\Closure::class === $args[1] || is_subclass_of($args[1], '\\' . \Closure::class), 'Expect object class name to be Closure or a subclass of Closure.'); |
||
| 126 | |||
| 127 | $this->assertSame(['array', [['integer', 1], ['integer', 2]]], $array[$i++]); |
||
| 128 | $this->assertSame(['array', ['foo' => ['integer', 123]]], $array[$i++]); |
||
| 129 | $this->assertSame(['null', null], $array[$i++]); |
||
| 130 | $this->assertSame(['boolean', true], $array[$i++]); |
||
| 131 | $this->assertSame(['boolean', false], $array[$i++]); |
||
| 132 | $this->assertSame(['integer', 0], $array[$i++]); |
||
| 133 | $this->assertSame(['float', 0.0], $array[$i++]); |
||
| 134 | $this->assertSame(['string', '0'], $array[$i++]); |
||
| 135 | $this->assertSame(['string', ''], $array[$i++]); |
||
| 136 | $this->assertSame(['float', INF], $array[$i++]); |
||
| 137 | |||
| 138 | // assertEquals() does not like NAN values. |
||
| 139 | $this->assertEquals('float', $array[$i][0]); |
||
| 140 | $this->assertNan($array[$i++][1]); |
||
| 141 | } |
||
| 196 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.