Skip to content

Instantly share code, notes, and snippets.

@mageekguy
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mageekguy/9931546 to your computer and use it in GitHub Desktop.
Save mageekguy/9931546 to your computer and use it in GitHub Desktop.
<?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