Next coding dojo solution#3
Next coding dojo solution#3MarcinGladkowski wants to merge 87 commits intoCodingDojoSilesia:masterfrom
Conversation
|
|
||
| RUN composer install --no-interaction | ||
|
|
||
| COPY . . |
There was a problem hiding this comment.
Isn't a good idea:
- Without .dockerignore you're copy anything from context directory, with
.envor temporary builded files. COPY . .triggers on each changing in context directory - It could be problem with cacheing layer.
| public function __invoke(BuyItemRequest $request): ConsoleResponse | ||
| { | ||
| $item = $request->item(); | ||
| $moneys = $request->moneyCollection(); |
There was a problem hiding this comment.
money is a plural form. So you should rename to money_collection
| public function __construct( | ||
| private ItemRepository $itemRepository, | ||
| private PaymentCoordinator $paymentCoordinator, | ||
| private ConsoleResponse $response |
There was a problem hiding this comment.
you should have Response or IResponse class, ConsoleResponse tells about specified implementation.
| if ($availableItem->enoughToBuy($moneys->count())) { | ||
| $this->response->setProduct($availableItem); | ||
|
|
||
| return $this->response->setRest( |
There was a problem hiding this comment.
I think, you should return a new response, not generate response / part of response from response.
my propositions:
return $this->responseFactory->createRestResponse($availableItem, ...);or
return new RestResponse($availableItem, ...);
# The controller of commands should get response and use it.Disadvantage of your solution is to use N methods to fill a response. What if you add next method like setDiscount and forgot to update this command?
| { | ||
| public function pay(int $input, int $cost): MoneyCollection | ||
| { | ||
| if ($input >= $cost) { |
There was a problem hiding this comment.
I prefer IfError pattern. Is more easy to write method with validating as first.
| ); | ||
|
|
||
| self::assertEquals(0, $result->rest()->count()); | ||
| } |
There was a problem hiding this comment.
You wrote only happy path cases. Where are cases to support errors like not enough money?
| $availableItem = $this->itemRepository->getItemBySelector($item); | ||
|
|
||
| if (!$availableItem) { | ||
| throw new \InvalidArgumentException(sprintf('Item %s is not available', $item)); |
There was a problem hiding this comment.
I thinking about this exception - exceptions should be for unexpected situations (like disconnect, file not found, index larger than size of array etc) and not availabled item is an expected situation by business flow so I think it should be as:
return new ItemNotAvailableResponse($item);PS. As functional programmer, I don't like exceptions ; -)
|
|
||
| $result = $command(new CoinReturnRequest($moneyCollection)); | ||
|
|
||
| self::assertEquals('D, DOLLAR', $result); |
| { | ||
| $request = $this->parser->parse('Q, Q, Q, Q, GET-B'); | ||
|
|
||
| self::assertInstanceOf(ConsoleRequest::class, $request); |
There was a problem hiding this comment.
Is not a enough to check class - What is in request inside?
| { | ||
| $vm = new VendingMachine(); | ||
| $this->vendingMachine = $vm; | ||
| $itemRepositoryMock = $this->getMockBuilder(ItemRepository::class)->getMock(); |
No description provided.