| Conditions | 1 |
| Paths | 1 |
| Total Lines | 69 |
| Code Lines | 50 |
| 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 |
||
| 44 | public function testPersist() |
||
| 45 | { |
||
| 46 | $this |
||
| 47 | ->given($repository = $this->createRepository()) |
||
| 48 | ->and( |
||
| 49 | $post = PostEventSourcedFactory::create( |
||
| 50 | $this->faker->sentence, |
||
| 51 | $this->faker->paragraph |
||
| 52 | ) |
||
| 53 | ) |
||
| 54 | ->and($post->changeTitle($this->faker->sentence)) |
||
| 55 | ->when($repository->persist($post)) |
||
| 56 | ->then() |
||
| 57 | ->object($repository->get($post->id())) |
||
| 58 | ->isEqualTo($post) |
||
| 59 | ; |
||
| 60 | |||
| 61 | $this |
||
| 62 | ->given($repository = $this->createRepository()) |
||
| 63 | ->and( |
||
| 64 | $post = PostEventSourcedFactory::create( |
||
| 65 | $this->faker->sentence, |
||
| 66 | $this->faker->paragraph |
||
| 67 | ) |
||
| 68 | ) |
||
| 69 | ->and($post->clearEvents()) |
||
| 70 | ->when($repository->persist($post)) |
||
| 71 | ->then() |
||
| 72 | ->exception(function () use ($repository, $post) { |
||
| 73 | $repository->get($post->id()); |
||
| 74 | }) |
||
| 75 | ->isInstanceOf(\RuntimeException::class) |
||
| 76 | ; |
||
| 77 | |||
| 78 | $this |
||
| 79 | ->given($repository = $this->createRepository()) |
||
| 80 | ->and( |
||
| 81 | $post = new Post( |
||
| 82 | PostId::fromNative(md5(rand())), |
||
| 83 | $this->faker->sentence, |
||
| 84 | $this->faker->paragraph |
||
| 85 | ) |
||
| 86 | ) |
||
| 87 | ->then() |
||
| 88 | ->exception(function () use ($repository, $post) { |
||
| 89 | $repository->persist($post); |
||
| 90 | }) |
||
| 91 | ->isInstanceOf(\InvalidArgumentException::class) |
||
| 92 | ; |
||
| 93 | |||
| 94 | $this |
||
| 95 | ->given($repository = $this->createRepository()) |
||
| 96 | ->and( |
||
| 97 | $post = PostEventSourcedFactory::create( |
||
| 98 | $this->faker->sentence, |
||
| 99 | $this->faker->paragraph |
||
| 100 | ) |
||
| 101 | ) |
||
| 102 | ->and($post->changeTitle($this->faker->sentence)) |
||
| 103 | ->and($prePersistSubscriber = new PrePersistSubscriber(42)) |
||
| 104 | ->and($postPersistSubscriber = new PostPersistSubscriber()) |
||
| 105 | ->and(DomainEventPublisher::subscribe($prePersistSubscriber)) |
||
| 106 | ->and(DomainEventPublisher::subscribe($postPersistSubscriber)) |
||
| 107 | ->when($repository->persist($post)) |
||
| 108 | ->then() |
||
| 109 | ->integer($post->version()->patch()) |
||
| 110 | ->isEqualTo(84) |
||
| 111 | ; |
||
| 112 | } |
||
| 113 | |||
| 207 |