Conditions | 2 |
Paths | 2 |
Total Lines | 68 |
Code Lines | 43 |
Lines | 14 |
Ratio | 20.59 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
156 | public function testSubEntityRelations() |
||
157 | { |
||
158 | $repository = $this->getManager()->getRepository(SubEntity::class); |
||
159 | |||
160 | $this->getClient('test-client')->push( |
||
161 | $this->getResponseMock( |
||
162 | true, |
||
163 | (object)[ |
||
164 | 'id' => '1', |
||
165 | 'payload' => 'test-payload', |
||
166 | 'references' => ['5', '7'], |
||
167 | 'sub-payload' => 'sub-payload', |
||
168 | ] |
||
169 | ), |
||
170 | function (RpcRequestInterface $request) { |
||
171 | self::assertEquals('test-entity/find', $request->getMethod()); |
||
172 | self::assertEquals(['id' => 1], $request->getParameters()); |
||
173 | |||
174 | return true; |
||
175 | } |
||
176 | ); |
||
177 | |||
178 | $this->getClient('test-reference-client')->push( |
||
179 | $this->getResponseMock( |
||
180 | true, |
||
181 | [ |
||
182 | (object)[ |
||
183 | 'id' => '5', |
||
184 | 'reference-payload' => 'test-payload-5', |
||
185 | 'owner' => '1', |
||
186 | ], |
||
187 | (object)[ |
||
188 | 'id' => '7', |
||
189 | 'reference-payload' => 'test-payload-7', |
||
190 | 'owner' => '1', |
||
191 | ], |
||
192 | ] |
||
193 | ), |
||
194 | View Code Duplication | function (RpcRequestInterface $request) { |
|
195 | self::assertEquals('test-reference/search', $request->getMethod()); |
||
196 | self::assertEquals( |
||
197 | [ |
||
198 | 'criteria' => ['owner' => 1], |
||
199 | 'order' => [], |
||
200 | 'limit' => null, |
||
201 | 'offset' => null, |
||
202 | ], |
||
203 | $request->getParameters() |
||
204 | ); |
||
205 | |||
206 | return true; |
||
207 | } |
||
208 | ); |
||
209 | |||
210 | /** @var SubEntity $entity */ |
||
211 | $entity = $repository->find(1); |
||
212 | self::assertSame(1, $entity->getId()); |
||
213 | self::assertSame('test-payload', $entity->getPayload()); |
||
214 | self::assertSame('sub-payload', $entity->getSubPayload()); |
||
215 | self::assertNull($entity->getStringPayload()); |
||
216 | /** @var TestReference[] $references */ |
||
217 | $references = $entity->getReferences()->toArray(); |
||
218 | |||
219 | self::assertCount(2, $references); |
||
220 | foreach ($references as $reference) { |
||
221 | self::assertSame('test-payload-' . $reference->getId(), $reference->getReferencePayload()); |
||
222 | } |
||
223 | } |
||
224 | |||
230 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: