| Conditions | 1 |
| Paths | 1 |
| Total Lines | 77 |
| 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 |
||
| 90 | public function shouldBuildCallArguments() |
||
| 91 | { |
||
| 92 | /** @var ReflectionMethod $methodReflection */ |
||
| 93 | $methodReflection = $this->createMock(ReflectionMethod::class); |
||
| 94 | |||
| 95 | /** @var ReflectionParameter $parameterFooReflection */ |
||
| 96 | $parameterFooReflection = $this->createMock(ReflectionParameter::class); |
||
| 97 | $parameterFooReflection->method('getName')->willReturn("foo"); |
||
| 98 | |||
| 99 | /** @var ReflectionParameter $parameterBarReflection */ |
||
| 100 | $parameterBarReflection = $this->createMock(ReflectionParameter::class); |
||
| 101 | $parameterBarReflection->method('getName')->willReturn("bar"); |
||
| 102 | |||
| 103 | /** @var ReflectionParameter $parameterBazReflection */ |
||
| 104 | $parameterBazReflection = $this->createMock(ReflectionParameter::class); |
||
| 105 | $parameterBazReflection->method('getName')->willReturn("baz"); |
||
| 106 | |||
| 107 | /** @var ReflectionType $parameterType */ |
||
| 108 | $parameterType = $this->createMock(ReflectionType::class); |
||
| 109 | $parameterType->method('__toString')->willReturn(stdClass::class); |
||
| 110 | |||
| 111 | /** @var ReflectionParameter $parameterBazReflection */ |
||
| 112 | $parameterFazReflection = $this->createMock(ReflectionParameter::class); |
||
| 113 | $parameterFazReflection->method('getName')->willReturn("faz"); |
||
| 114 | $parameterFazReflection->method('hasType')->willReturn(true); |
||
| 115 | $parameterFazReflection->method('getType')->willReturn($parameterType); |
||
| 116 | |||
| 117 | $methodReflection->method("getParameters")->willReturn([ |
||
| 118 | $parameterFooReflection, |
||
| 119 | $parameterBarReflection, |
||
| 120 | $parameterBazReflection, |
||
| 121 | $parameterFazReflection |
||
| 122 | ]); |
||
| 123 | |||
| 124 | /** @var Request $request */ |
||
| 125 | $request = $this->createMock(Request::class); |
||
| 126 | $request->method('get')->will($this->returnValueMap([ |
||
| 127 | ['lorem', null, 'ipsum'], |
||
| 128 | ['bar', null, 'blah'], |
||
| 129 | ])); |
||
| 130 | |||
| 131 | /** @var array<string, mixed> $argumentsConfiguration */ |
||
| 132 | $argumentsConfiguration = array( |
||
| 133 | "foo" => '$lorem', |
||
| 134 | "baz" => '@some.service', |
||
| 135 | "faz" => '$lorem' |
||
| 136 | ); |
||
| 137 | |||
| 138 | /** @var object $someService */ |
||
| 139 | $someService = new stdClass(); |
||
| 140 | |||
| 141 | $this->container->method('get')->will($this->returnValueMap([ |
||
| 142 | ['some.service', $someService], |
||
| 143 | ])); |
||
| 144 | |||
| 145 | $this->entityRepository->expects($this->once())->method('findEntity')->with( |
||
| 146 | $this->equalTo(stdClass::class), |
||
| 147 | $this->equalTo('ipsum') |
||
| 148 | )->willReturn($someService); |
||
| 149 | |||
| 150 | /** @var array<int, mixed> $expectedCallArguments */ |
||
| 151 | $expectedCallArguments = array( |
||
| 152 | 'ipsum', |
||
| 153 | 'blah', |
||
| 154 | $someService, |
||
| 155 | $someService |
||
| 156 | ); |
||
| 157 | |||
| 158 | /** @var array<int, mixed> $actualCallArguments */ |
||
| 159 | $actualCallArguments = $this->argumentCompiler->buildCallArguments( |
||
| 160 | $methodReflection, |
||
| 161 | $argumentsConfiguration, |
||
| 162 | $request |
||
| 163 | ); |
||
| 164 | |||
| 165 | $this->assertEquals($expectedCallArguments, $actualCallArguments); |
||
| 166 | } |
||
| 167 | |||
| 226 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..