Skip to content
This repository was archived by the owner on Jun 3, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .idea/php-docker-settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/php-test-framework.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

85 changes: 85 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Bread.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php declare(strict_types=1);
namespace ClansOfCaledonia;

final class Bread extends Good
{
public function isBread(): bool
{
return true;
}
}
10 changes: 10 additions & 0 deletions src/Cheese.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php declare(strict_types=1);
namespace ClansOfCaledonia;

final class Cheese extends Good
{
public function isCheese(): bool
{
return true;
}
}
45 changes: 45 additions & 0 deletions src/Good.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,53 @@ public static function milk(): self
return new Milk;
}

public static function bread(): self
{
return new Bread;
}

public static function whisky(): self
{
return new Whisky;
}

public static function cheese(): self
{
return new Cheese;
}

public static function wool(): self
{
return new Wool;
}

public static function grain(): self
{
return new Grain;
}

public function isWhisky(): bool
{
return false;
}

public function isBread(): bool
{
return false;
}

public function isWool(): bool
{
return false;
}

public function isMilk(): bool
{
return false;
}

public function isCheese(): bool
{
return false;
}
}
10 changes: 10 additions & 0 deletions src/Grain.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php declare(strict_types=1);
namespace ClansOfCaledonia;

final class Grain extends Good
{
public function isGrain(): bool
{
return true;
}
}
31 changes: 27 additions & 4 deletions src/Market.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,38 @@

final class Market
{
public function priceFor(Good $milk): Pound
/**
* @var PriceList
*/
private $milkPrices;
/**
* @var PriceList
*/
private $whiskyPrices;

public function __construct(PriceList $milkPrices, PriceList $whiskyPrices)
{
return new Pound(5);
$this->milkPrices = $milkPrices;
$this->whiskyPrices = $whiskyPrices;
}

public function priceFor(Good $good): Pound
{
if($good->isMilk()){
return $this->milkPrices->current();
}

if($good->isWhisky()){
return $this->whiskyPrices->current();
}
}

public function sellTo(Offer $offer): Pound
{
return new Pound(
$offer->amount()->amount() *
return (new Pound(
$offer->amount()->amount()
))
->multiply(
$this->priceFor($offer->good())->amount()
);
}
Expand Down
5 changes: 5 additions & 0 deletions src/Pound.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ public function amount(): int
{
return $this->amount;
}

public function multiply(int $multiplier)
{
return new self($this->amount * $multiplier);
}
}
12 changes: 12 additions & 0 deletions src/PriceList.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,16 @@ public function current(): Pound
{
return $this->prices[$this->position];
}

public function decrement(int $steps = 1)
{
$this->position -= $steps;
return $this->position;
}

public function increment(int $steps = 1)
{
$this->position += $steps;
return $this->position;
}
}
81 changes: 81 additions & 0 deletions src/PriceListBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,38 @@

final class PriceListBuilder
{
public function woolPrices(): PriceList
{
return PriceList::fromList(
new Pound(3),
new Pound(3),
new Pound(4),
new Pound(4),
new Pound(5),
new Pound(5),
new Pound(6),
new Pound(6),
new Pound(7),
new Pound(8)
);
}

public function grainPrices(): PriceList
{
return PriceList::fromList(
new Pound(3),
new Pound(3),
new Pound(4),
new Pound(5),
new Pound(6),
new Pound(6),
new Pound(7),
new Pound(7),
new Pound(8),
new Pound(8)
);
}

public function milkPrices(): PriceList
{
return PriceList::fromList(
Expand All @@ -18,4 +50,53 @@ public function milkPrices(): PriceList
new Pound(8)
);
}

public function breadPrices(): PriceList
{
return PriceList::fromList(
new Pound(7),
new Pound(8),
new Pound(9),
new Pound(10),
new Pound(11),
new Pound(11),
new Pound(12),
new Pound(13),
new Pound(14),
new Pound(15)
);
}

public function cheesePrices(): PriceList
{
return PriceList::fromList(
new Pound(7),
new Pound(8),
new Pound(9),
new Pound(10),
new Pound(11),
new Pound(12),
new Pound(13),
new Pound(14),
new Pound(14),
new Pound(15)
);
}

public function whiskyPrices(): PriceList
{
return PriceList::fromList(
new Pound(8),
new Pound(9),
new Pound(10),
new Pound(11),
new Pound(12),
new Pound(13),
new Pound(13),
new Pound(14),
new Pound(15),
new Pound(16)
);
}

}
10 changes: 10 additions & 0 deletions src/Whisky.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php declare(strict_types=1);
namespace ClansOfCaledonia;

final class Whisky extends Good
{
public function isWhisky(): bool
{
return true;
}
}
Loading