| Conditions | 1 |
| Paths | 1 |
| Total Lines | 58 |
| Code Lines | 44 |
| 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 |
||
| 148 | public function testRemove() |
||
| 149 | { |
||
| 150 | $this |
||
| 151 | ->given($repository = $this->createRepository()) |
||
| 152 | ->and( |
||
| 153 | $post = PostEventSourcedFactory::create( |
||
| 154 | $this->faker->sentence, |
||
| 155 | $this->faker->paragraph |
||
| 156 | ) |
||
| 157 | ) |
||
| 158 | ->and($post->changeTitle($this->faker->sentence)) |
||
| 159 | ->when($repository->persist($post)) |
||
| 160 | ->then() |
||
| 161 | ->object($repository->get($post->id())) |
||
| 162 | ->isEqualTo($post) |
||
| 163 | ->and() |
||
| 164 | ->when($repository->remove($post)) |
||
| 165 | ->then() |
||
| 166 | ->exception(function () use ($repository, $post) { |
||
| 167 | $repository->get($post->id()); |
||
| 168 | })->isInstanceOf(\RuntimeException::class) |
||
| 169 | ; |
||
| 170 | |||
| 171 | $this |
||
| 172 | ->given($repository = $this->createRepository()) |
||
| 173 | ->and( |
||
| 174 | $post = new Post( |
||
| 175 | PostId::fromNative(md5(rand())), |
||
| 176 | $this->faker->sentence, |
||
| 177 | $this->faker->paragraph |
||
| 178 | ) |
||
| 179 | ) |
||
| 180 | ->then() |
||
| 181 | ->exception(function () use ($repository, $post) { |
||
| 182 | $repository->remove($post); |
||
| 183 | }) |
||
| 184 | ->isInstanceOf(\InvalidArgumentException::class) |
||
| 185 | ; |
||
| 186 | |||
| 187 | $this |
||
| 188 | ->given($repository = $this->createRepository()) |
||
| 189 | ->and( |
||
| 190 | $post = PostEventSourcedFactory::create( |
||
| 191 | $this->faker->sentence, |
||
| 192 | $this->faker->paragraph |
||
| 193 | ) |
||
| 194 | ) |
||
| 195 | ->and($repository->persist($post)) |
||
| 196 | ->and($preRemoveSubscriber = new PreRemoveSubscriber(42)) |
||
| 197 | ->and($postRemoveSubscriber = new PostRemoveSubscriber()) |
||
| 198 | ->and(DomainEventPublisher::subscribe($preRemoveSubscriber)) |
||
| 199 | ->and(DomainEventPublisher::subscribe($postRemoveSubscriber)) |
||
| 200 | ->when($repository->remove($post)) |
||
| 201 | ->then() |
||
| 202 | ->integer($post->version()->patch()) |
||
| 203 | ->isEqualTo(21) |
||
| 204 | ; |
||
| 205 | } |
||
| 206 | } |
||
| 207 |