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