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