Last active
August 29, 2015 13:58
-
-
Save mageekguy/9931546 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace disneyland; | |
class client | |
{ | |
private $age = 0; | |
private $children = 0; | |
private $isFirm = false; | |
public function __construct($age, $chilren = 0, $isFirm = false) | |
{ | |
$this->age = $age; | |
$this->children = 0; | |
$this->isFirm = $isFirm; | |
} | |
public function computePrice($basePrice) | |
{ | |
$price = $basePrice * ($this->age < 10 ? 0.5 : $this->age < 18 ? 0.75 : 1); | |
if ($this->children > 3) | |
{ | |
$price *= 0.8; | |
} | |
if ($this->isFirm === true) | |
{ | |
$price *= 0.9; | |
} | |
return $price; | |
} | |
} | |
class order | |
{ | |
private $client = null; | |
private $tickets = 0; | |
private $date = null; | |
public function __construct(client $client, $tickets, $date = null) | |
{ | |
$this->client = $client; | |
$this->date = new \dateTime(); | |
$this->tickets = $tickets; | |
} | |
public function computePrice($basePrice) | |
{ | |
$price = $this->client->computePrice($basePrice) * $this->tickets; | |
switch ($this->date->getMonth()) | |
{ | |
case 6: | |
case 7: | |
case 8: | |
$price *= 1.25; | |
break; | |
} | |
if ($this->tickets > 10) | |
{ | |
$price *= 0.8; | |
} | |
if (new \dateTime() - $this->date < 10) | |
{ | |
$price *= 0.75; | |
} | |
return $price; | |
} | |
} | |
class quotation | |
{ | |
private $basePrice = 0.0; | |
public function __construct($basePrice) | |
{ | |
$this->basePrice = $basePrice; | |
} | |
public function computePrice(order $order) | |
{ | |
return (rand(1, 6) == 3 ? 0 : $order->computePrice($this->basePrice)); | |
} | |
} | |
$price = (new quotation(75))->computePrice(new order(new client(21), 4)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment