| Conditions | 1 |
| Paths | 1 |
| Total Lines | 52 |
| Code Lines | 31 |
| 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 |
||
| 91 | public function testChainUpdateWithRelation() |
||
| 92 | { |
||
| 93 | $entity = $this->testChainCommitWithRelation(); |
||
| 94 | |||
| 95 | $oldParent = $entity->getOwner(); |
||
| 96 | $newParent = new TestEntity(); |
||
| 97 | $this->getClient()->push( |
||
| 98 | $this->getResponseMock(true, 17), |
||
| 99 | function (RpcRequestInterface $request) { |
||
| 100 | self::assertEquals('test-entity/create', $request->getMethod()); |
||
| 101 | self::assertEquals( |
||
| 102 | [ |
||
| 103 | 'payload' => '', |
||
| 104 | 'parent' => null, |
||
| 105 | ], |
||
| 106 | $request->getParameters() |
||
| 107 | ); |
||
| 108 | |||
| 109 | return true; |
||
| 110 | } |
||
| 111 | ); |
||
| 112 | $this->getClient('test-reference-client')->push( |
||
| 113 | $this->getResponseMock(true, null), |
||
| 114 | function (RpcRequestInterface $request) { |
||
| 115 | self::assertEquals('test-reference/patch', $request->getMethod()); |
||
| 116 | self::assertEquals( |
||
| 117 | [ |
||
| 118 | 'owner' => 17, |
||
| 119 | ], |
||
| 120 | $request->getParameters() |
||
| 121 | ); |
||
| 122 | |||
| 123 | return true; |
||
| 124 | } |
||
| 125 | ); |
||
| 126 | |||
| 127 | $entity->setOwner($newParent); |
||
| 128 | |||
| 129 | $this->getManager()->persist($newParent); |
||
| 130 | $this->getManager()->flush(); |
||
| 131 | |||
| 132 | self::assertNotNull($newParent->getId()); |
||
| 133 | self::assertEquals(17, $newParent->getId()); |
||
| 134 | |||
| 135 | self::assertNotNull($entity->getId()); |
||
| 136 | self::assertEquals(241, $entity->getId()); |
||
| 137 | |||
| 138 | self::assertEquals($entity->getOwner(), $newParent); |
||
| 139 | |||
| 140 | self::assertNotSame($newParent, $oldParent); |
||
| 141 | self::assertFalse($oldParent->getReferences()->contains($entity)); |
||
| 142 | } |
||
| 143 | |||
| 167 |