| Conditions | 1 |
| Paths | 1 |
| Total Lines | 55 |
| 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 |
||
| 25 | public function testInterceptorGenerator() : void |
||
| 26 | { |
||
| 27 | $method = $this->createMock(MethodGenerator::class); |
||
|
|
|||
| 28 | $bar = $this->createMock(ParameterGenerator::class); |
||
| 29 | $baz = $this->createMock(ParameterGenerator::class); |
||
| 30 | $valueHolder = $this->createMock(PropertyGenerator::class); |
||
| 31 | $prefixInterceptors = $this->createMock(PropertyGenerator::class); |
||
| 32 | $suffixInterceptors = $this->createMock(PropertyGenerator::class); |
||
| 33 | |||
| 34 | $bar->method('getName')->willReturn('bar'); |
||
| 35 | $baz->method('getName')->willReturn('baz'); |
||
| 36 | $method->method('getName')->willReturn('fooMethod'); |
||
| 37 | $method->method('getParameters')->will(self::returnValue([$bar, $baz])); |
||
| 38 | $valueHolder->method('getName')->willReturn('foo'); |
||
| 39 | $prefixInterceptors->method('getName')->willReturn('pre'); |
||
| 40 | $suffixInterceptors->method('getName')->willReturn('post'); |
||
| 41 | |||
| 42 | // @codingStandardsIgnoreStart |
||
| 43 | $expected = <<<'PHP' |
||
| 44 | if (isset($this->pre['fooMethod'])) { |
||
| 45 | $returnEarly = false; |
||
| 46 | $prefixReturnValue = $this->pre['fooMethod']->__invoke($this, $this->foo, 'fooMethod', array('bar' => $bar, 'baz' => $baz), $returnEarly); |
||
| 47 | |||
| 48 | if ($returnEarly) { |
||
| 49 | return $prefixReturnValue; |
||
| 50 | } |
||
| 51 | } |
||
| 52 | |||
| 53 | $returnValue = "foo"; |
||
| 54 | |||
| 55 | if (isset($this->post['fooMethod'])) { |
||
| 56 | $returnEarly = false; |
||
| 57 | $suffixReturnValue = $this->post['fooMethod']->__invoke($this, $this->foo, 'fooMethod', array('bar' => $bar, 'baz' => $baz), $returnValue, $returnEarly); |
||
| 58 | |||
| 59 | if ($returnEarly) { |
||
| 60 | return $suffixReturnValue; |
||
| 61 | } |
||
| 62 | } |
||
| 63 | |||
| 64 | return $returnValue; |
||
| 65 | PHP; |
||
| 66 | // @codingStandardsIgnoreEnd |
||
| 67 | |||
| 68 | self::assertSame( |
||
| 69 | $expected, |
||
| 70 | InterceptorGenerator::createInterceptedMethodBody( |
||
| 71 | '$returnValue = "foo";', |
||
| 72 | $method, |
||
| 73 | $valueHolder, |
||
| 74 | $prefixInterceptors, |
||
| 75 | $suffixInterceptors, |
||
| 76 | null |
||
| 77 | ) |
||
| 78 | ); |
||
| 79 | } |
||
| 80 | |||
| 196 |
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.