| Conditions | 1 |
| Paths | 1 |
| Total Lines | 51 |
| Code Lines | 45 |
| 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 |
||
| 45 | public function testCreate() |
||
| 46 | { |
||
| 47 | $eventStore = new InMemoryEventStore(); |
||
| 48 | $readModelRepository = new InMemoryQueryRepository(PublishedPost::class); |
||
| 49 | $writeModelRepository = new AggregateRepository($eventStore, PostEventSourced::class); |
||
| 50 | |||
| 51 | $this |
||
| 52 | ->given($projector = $this->createProjector($readModelRepository, $eventStore)) |
||
| 53 | ->and(DomainEventPublisher::subscribe($projector)) |
||
| 54 | ->and( |
||
| 55 | $postId = PostId::fromNative(md5(rand())), |
||
| 56 | $writeModel = new PostEventSourced( |
||
| 57 | $postId, |
||
| 58 | 'The post title', |
||
| 59 | 'The post description' |
||
| 60 | ) |
||
| 61 | ) |
||
| 62 | ->then() |
||
| 63 | ->boolean($readModelRepository->isEmpty()) |
||
| 64 | ->isTrue() |
||
| 65 | ->and() |
||
| 66 | ->when($writeModelRepository->persist($writeModel)) |
||
| 67 | ->then() |
||
| 68 | ->boolean($readModelRepository->isEmpty()) |
||
| 69 | ->isTrue() |
||
| 70 | ->and() |
||
| 71 | ->when($writeModel->publish()) |
||
| 72 | ->and($writeModelRepository->persist($writeModel)) |
||
| 73 | ->then() |
||
| 74 | ->boolean($readModelRepository->isEmpty()) |
||
| 75 | ->isFalse() |
||
| 76 | ->object($readModel = $readModelRepository->findOne(Criteria::property('id')->eq($postId))) |
||
| 77 | ->isInstanceOf(PublishedPost::class) |
||
| 78 | ->string($readModel->title()) |
||
| 79 | ->isEqualTo('The post title') |
||
| 80 | ->and() |
||
| 81 | ->when($writeModel->changeTitle('foo')) |
||
| 82 | ->and($writeModelRepository->persist($writeModel)) |
||
| 83 | ->then() |
||
| 84 | ->object($readModel = $readModelRepository->findOne(Criteria::property('id')->eq($postId))) |
||
| 85 | ->isInstanceOf(PublishedPost::class) |
||
| 86 | ->string($readModel->title()) |
||
| 87 | ->isEqualTo('foo') |
||
| 88 | ->and() |
||
| 89 | ->when($writeModel->unpublish()) |
||
| 90 | ->and($writeModelRepository->persist($writeModel)) |
||
| 91 | ->then() |
||
| 92 | ->boolean($readModelRepository->isEmpty()) |
||
| 93 | ->isTrue() |
||
| 94 | ; |
||
| 95 | } |
||
| 96 | } |
||
| 97 |