| Conditions | 1 |
| Paths | 1 |
| Total Lines | 58 |
| 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 testInterceptorGeneratorWithVoidMethod() : void |
||
| 82 | { |
||
| 83 | $method = $this->createMock(MethodGenerator::class); |
||
| 84 | $bar = $this->createMock(ParameterGenerator::class); |
||
| 85 | $baz = $this->createMock(ParameterGenerator::class); |
||
| 86 | $valueHolder = $this->createMock(PropertyGenerator::class); |
||
| 87 | $prefixInterceptors = $this->createMock(PropertyGenerator::class); |
||
| 88 | $suffixInterceptors = $this->createMock(PropertyGenerator::class); |
||
| 89 | |||
| 90 | $bar->method('getName')->willReturn('bar'); |
||
| 91 | $baz->method('getName')->willReturn('baz'); |
||
| 92 | $method->method('getName')->willReturn('fooMethod'); |
||
| 93 | $method->method('getParameters')->will(self::returnValue([$bar, $baz])); |
||
| 94 | $valueHolder->method('getName')->willReturn('foo'); |
||
| 95 | $prefixInterceptors->method('getName')->willReturn('pre'); |
||
| 96 | $suffixInterceptors->method('getName')->willReturn('post'); |
||
| 97 | |||
| 98 | // @codingStandardsIgnoreStart |
||
| 99 | $expected = <<<'PHP' |
||
| 100 | if (isset($this->pre['fooMethod'])) { |
||
| 101 | $returnEarly = false; |
||
| 102 | $prefixReturnValue = $this->pre['fooMethod']->__invoke($this, $this->foo, 'fooMethod', array('bar' => $bar, 'baz' => $baz), $returnEarly); |
||
| 103 | |||
| 104 | if ($returnEarly) { |
||
| 105 | $prefixReturnValue; |
||
| 106 | return; |
||
| 107 | } |
||
| 108 | } |
||
| 109 | |||
| 110 | $returnValue = "foo"; |
||
| 111 | |||
| 112 | if (isset($this->post['fooMethod'])) { |
||
| 113 | $returnEarly = false; |
||
| 114 | $suffixReturnValue = $this->post['fooMethod']->__invoke($this, $this->foo, 'fooMethod', array('bar' => $bar, 'baz' => $baz), $returnValue, $returnEarly); |
||
| 115 | |||
| 116 | if ($returnEarly) { |
||
| 117 | $suffixReturnValue; |
||
| 118 | return; |
||
| 119 | } |
||
| 120 | } |
||
| 121 | |||
| 122 | $returnValue; |
||
| 123 | return; |
||
| 124 | PHP; |
||
| 125 | // @codingStandardsIgnoreEnd |
||
| 126 | |||
| 127 | self::assertSame( |
||
| 128 | $expected, |
||
| 129 | InterceptorGenerator::createInterceptedMethodBody( |
||
| 130 | '$returnValue = "foo";', |
||
| 131 | $method, |
||
| 132 | $valueHolder, |
||
| 133 | $prefixInterceptors, |
||
| 134 | $suffixInterceptors, |
||
| 135 | new ReflectionMethod(VoidMethodTypeHintedInterface::class, 'returnVoid') |
||
| 136 | ) |
||
| 137 | ); |
||
| 138 | } |
||
| 139 | |||
| 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.