Skip to content

Commit

Permalink
Merge pull request #80 from mchekin/enforce-sell-only-stores
Browse files Browse the repository at this point in the history
Enforce sell-only stores
  • Loading branch information
mchekin authored Dec 20, 2021
2 parents ac73978 + 9dcad34 commit a74c973
Show file tree
Hide file tree
Showing 5 changed files with 756 additions and 728 deletions.
5 changes: 5 additions & 0 deletions app/Modules/Trade/Domain/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use App\Modules\Generic\Domain\Container\ContainerSlotOutOfRangeException;
use App\Modules\Generic\Domain\Container\ItemNotInContainer;
use App\Modules\Generic\Domain\Container\NotEnoughSpaceInContainerException;
use App\Modules\Trade\Domain\Store\StoreDoesNotBuyItems;
use Illuminate\Support\Collection;

class Store
Expand Down Expand Up @@ -145,6 +146,10 @@ public function putMoneyIn(Money $money): void

public function takeMoneyOut(Money $money): Money
{
if ($this->type->isSellOnly()) {
throw new StoreDoesNotBuyItems('Store does not buy items');
}

$this->money = $this->money->remove($money);

return $money;
Expand Down
11 changes: 11 additions & 0 deletions app/Modules/Trade/Domain/Store/StoreDoesNotBuyItems.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php declare(strict_types=1);


namespace App\Modules\Trade\Domain\Store;


use RuntimeException;

class StoreDoesNotBuyItems extends RuntimeException
{
}
5 changes: 2 additions & 3 deletions app/Modules/Trade/Domain/StoreType.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Modules\Trade\Domain;

use App\Modules\Equipment\Domain\ItemType;
use InvalidArgumentException;

class StoreType
Expand Down Expand Up @@ -49,8 +48,8 @@ public function toString(): string
return $this->type;
}

public function equals(ItemType $type): bool
public function isSellOnly(): bool
{
return $this->type === $type->toString();
return $this->type === self::SELL_ONLY;
}
}
Loading

0 comments on commit a74c973

Please sign in to comment.