| Conditions | 3 |
| Paths | 4 |
| Total Lines | 54 |
| Code Lines | 35 |
| Lines | 7 |
| Ratio | 12.96 % |
| 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 |
||
| 54 | public function testOneToManyLoading() |
||
| 55 | { |
||
| 56 | $repository = $this->getManager()->getRepository(TestEntity::class); |
||
| 57 | |||
| 58 | $this->getClient('test-client')->push( |
||
| 59 | $this->getResponseMock( |
||
| 60 | true, |
||
| 61 | (object)[ |
||
| 62 | 'id' => '1', |
||
| 63 | 'payload' => 'test-payload', |
||
| 64 | ] |
||
| 65 | ) |
||
| 66 | ); |
||
| 67 | |||
| 68 | $this->getClient('test-reference-client')->push( |
||
| 69 | $this->getResponseMock( |
||
| 70 | true, |
||
| 71 | [ |
||
| 72 | (object)[ |
||
| 73 | 'id' => '5', |
||
| 74 | 'reference-payload' => 'test-payload-5', |
||
| 75 | 'owner' => '1', |
||
| 76 | ], |
||
| 77 | (object)[ |
||
| 78 | 'id' => '7', |
||
| 79 | 'reference-payload' => 'test-payload-7', |
||
| 80 | 'owner' => '1', |
||
| 81 | ], |
||
| 82 | ] |
||
| 83 | ) |
||
| 84 | ); |
||
| 85 | |||
| 86 | /** @var TestEntity $entity */ |
||
| 87 | $entity = $repository->find(1); |
||
| 88 | |||
| 89 | self::assertInstanceOf(TestEntity::class, $entity); |
||
| 90 | self::assertEquals('test-payload', $entity->getPayload()); |
||
| 91 | self::assertEquals(1, $entity->getId()); |
||
| 92 | self::assertInstanceOf(Collection::class, $entity->getReferences()); |
||
| 93 | self::assertEquals(1, $this->getClient('test-reference-client')->count()); |
||
| 94 | self::assertCount(2, $entity->getReferences()); |
||
| 95 | self::assertEquals(0, $this->getClient('test-reference-client')->count()); |
||
| 96 | foreach ($entity->getReferences() as $reference) { |
||
| 97 | } |
||
| 98 | self::assertInstanceOf(Collection::class, $entity->getReferences()); |
||
| 99 | |||
| 100 | View Code Duplication | foreach ($entity->getReferences() as $reference) { |
|
| 101 | self::assertInternalType('int', $reference->getId()); |
||
| 102 | self::assertInternalType('int', $reference->getOwner()->getId()); |
||
| 103 | self::assertInstanceOf(TestReference::class, $reference); |
||
| 104 | self::assertEquals('test-payload-'.$reference->getId(), $reference->getReferencePayload()); |
||
| 105 | self::assertEquals($entity, $reference->getOwner()); |
||
| 106 | } |
||
| 107 | } |
||
| 108 | |||
| 209 |
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: