Conditions | 1 |
Paths | 1 |
Total Lines | 63 |
Code Lines | 51 |
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 |
||
72 | public function testLoad() |
||
73 | { |
||
74 | $this |
||
75 | ->given($store = $this->createStore()) |
||
76 | ->and($postId = PostId::fromNative(md5(rand()))) |
||
77 | ->and($postId1 = PostId::fromNative(md5(rand()))) |
||
78 | ->and($streamName = 'Posts-'.$postId) |
||
79 | ->and($streamName1 = 'Posts-'.$postId1) |
||
80 | ->and( |
||
81 | $postWasCreated = new PostWasCreated($postId1, 'foo', 'bar'), |
||
82 | $postWasCreated->setVersion(1) |
||
83 | ) |
||
84 | ->and( |
||
85 | $postTitleWasChanged = new PostTitleWasChanged($postId1, 'new title'), |
||
86 | $postTitleWasChanged->setVersion(2) |
||
87 | ) |
||
88 | ->and($streamNameFake = 'Blogs-'.$postId) |
||
89 | ->and($eventStream = new EventStream($streamName, $postId, [])) |
||
90 | ->and($eventStream1 = new EventStream($streamName1, $postId1, [$postWasCreated, $postTitleWasChanged])) |
||
91 | ->when($store->persist($eventStream)) |
||
92 | ->then() |
||
93 | ->variable($store->load($streamName)) |
||
94 | ->isNull() |
||
95 | ->variable($store->load($streamNameFake)) |
||
96 | ->isNull() |
||
97 | ->and() |
||
98 | ->when($store->persist($eventStream1)) |
||
99 | ->and($result = $store->load($streamName1)) |
||
100 | ->then() |
||
101 | ->object($result->aggregateId()) |
||
102 | ->isEqualTo($eventStream1->aggregateId()) |
||
103 | ; |
||
104 | |||
105 | $this |
||
106 | ->given($store = $this->createStore()) |
||
107 | ->and($postId = PostId::fromNative(md5(rand()))) |
||
108 | ->and($streamName = 'Posts-'.$postId) |
||
109 | ->and( |
||
110 | $postWasCreated = new PostWasCreated($postId, 'foo', 'bar'), |
||
111 | $postWasCreated->setVersion(1) |
||
112 | ) |
||
113 | ->and( |
||
114 | $postTitleWasChanged = new PostTitleWasChanged($postId, 'new title'), |
||
115 | $postTitleWasChanged->setVersion(2) |
||
116 | ) |
||
117 | ->and( |
||
118 | $postTitleWasChangedAgain = new PostTitleWasChanged($postId, 'more title'), |
||
119 | $postTitleWasChangedAgain->setVersion(3) |
||
120 | ) |
||
121 | ->and( |
||
122 | $eventStream = new EventStream( |
||
123 | $streamName, |
||
124 | $postId, |
||
125 | [$postWasCreated, $postTitleWasChanged, $postTitleWasChangedAgain] |
||
126 | ) |
||
127 | ) |
||
128 | ->and($store->persist($eventStream)) |
||
129 | ->when($stream = $store->load($streamName, 2)) |
||
130 | ->then() |
||
131 | ->array($stream->events()) |
||
132 | ->hasSize(2) |
||
133 | ; |
||
134 | } |
||
135 | |||
168 |