| Conditions | 1 |
| Paths | 1 |
| Total Lines | 67 |
| Code Lines | 49 |
| 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 | ->variable($repository->get($post->id())) |
||
| 73 | ->isNull() |
||
| 74 | ; |
||
| 75 | |||
| 76 | $this |
||
| 77 | ->given($repository = $this->createRepository()) |
||
| 78 | ->and( |
||
| 79 | $post = new Post( |
||
| 80 | PostId::fromNative(md5(rand())), |
||
| 81 | $this->faker->sentence, |
||
| 82 | $this->faker->paragraph |
||
| 83 | ) |
||
| 84 | ) |
||
| 85 | ->then() |
||
| 86 | ->exception(function () use ($repository, $post) { |
||
| 87 | $repository->persist($post); |
||
| 88 | }) |
||
| 89 | ->isInstanceOf(\InvalidArgumentException::class) |
||
| 90 | ; |
||
| 91 | |||
| 92 | $this |
||
| 93 | ->given($repository = $this->createRepository()) |
||
| 94 | ->and( |
||
| 95 | $post = PostEventSourcedFactory::create( |
||
| 96 | $this->faker->sentence, |
||
| 97 | $this->faker->paragraph |
||
| 98 | ) |
||
| 99 | ) |
||
| 100 | ->and($post->changeTitle($this->faker->sentence)) |
||
| 101 | ->and($prePersistSubscriber = new PrePersistSubscriber(42)) |
||
| 102 | ->and($postPersistSubscriber = new PostPersistSubscriber()) |
||
| 103 | ->and(DomainEventPublisher::subscribe($prePersistSubscriber)) |
||
| 104 | ->and(DomainEventPublisher::subscribe($postPersistSubscriber)) |
||
| 105 | ->when($repository->persist($post)) |
||
| 106 | ->then() |
||
| 107 | ->integer($post->version()) |
||
| 108 | ->isEqualTo(84) |
||
| 109 | ; |
||
| 110 | } |
||
| 111 | |||
| 204 |