| Conditions | 1 |
| Paths | 1 |
| Total Lines | 52 |
| 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 |
||
| 134 | public function testInterceptorGeneratorWithExistingNonVoidMethod() : void |
||
| 135 | { |
||
| 136 | $method = $this->createMock(MethodGenerator::class); |
||
| 137 | $bar = $this->createMock(ParameterGenerator::class); |
||
| 138 | $baz = $this->createMock(ParameterGenerator::class); |
||
| 139 | $prefixInterceptors = $this->createMock(PropertyGenerator::class); |
||
| 140 | $suffixInterceptors = $this->createMock(PropertyGenerator::class); |
||
| 141 | |||
| 142 | $bar->method('getName')->willReturn('bar'); |
||
| 143 | $baz->method('getName')->willReturn('baz'); |
||
| 144 | $method->method('getName')->willReturn('fooMethod'); |
||
| 145 | $method->method('getParameters')->will(self::returnValue([$bar, $baz])); |
||
| 146 | $prefixInterceptors->method('getName')->willReturn('pre'); |
||
| 147 | $suffixInterceptors->method('getName')->willReturn('post'); |
||
| 148 | |||
| 149 | // @codingStandardsIgnoreStart |
||
| 150 | $expected = <<<'PHP' |
||
| 151 | if (isset($this->pre['fooMethod'])) { |
||
| 152 | $returnEarly = false; |
||
| 153 | $prefixReturnValue = $this->pre['fooMethod']->__invoke($this, $this, 'fooMethod', array('bar' => $bar, 'baz' => $baz), $returnEarly); |
||
| 154 | |||
| 155 | if ($returnEarly) { |
||
| 156 | return $prefixReturnValue; |
||
| 157 | } |
||
| 158 | } |
||
| 159 | |||
| 160 | $returnValue = "foo"; |
||
| 161 | |||
| 162 | if (isset($this->post['fooMethod'])) { |
||
| 163 | $returnEarly = false; |
||
| 164 | $suffixReturnValue = $this->post['fooMethod']->__invoke($this, $this, 'fooMethod', array('bar' => $bar, 'baz' => $baz), $returnValue, $returnEarly); |
||
| 165 | |||
| 166 | if ($returnEarly) { |
||
| 167 | return $suffixReturnValue; |
||
| 168 | } |
||
| 169 | } |
||
| 170 | |||
| 171 | return $returnValue; |
||
| 172 | PHP; |
||
| 173 | // @codingStandardsIgnoreEnd |
||
| 174 | |||
| 175 | self::assertSame( |
||
| 176 | $expected, |
||
| 177 | InterceptorGenerator::createInterceptedMethodBody( |
||
| 178 | '$returnValue = "foo";', |
||
| 179 | $method, |
||
| 180 | $prefixInterceptors, |
||
| 181 | $suffixInterceptors, |
||
| 182 | new ReflectionMethod(BaseClass::class, 'publicMethod') |
||
| 183 | ) |
||
| 184 | ); |
||
| 185 | } |
||
| 186 | } |
||
| 187 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.