Add PHP version of kata

This commit is contained in:
Sam Cranford
2020-02-09 12:10:16 +01:00
parent 6fe474d4ac
commit de37fb26a8
11 changed files with 1886 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
<?php
namespace Theatrical;
use Theatrical\Play;
use Theatrical\Invoice;
use Theatrical\Performance;
class StatementPrinter
{
public function print(Invoice $invoice, array $plays)
{
$totalAmount = 0;
$volumeCredits = 0;
$result = 'Statement for ' . $invoice->customer . '\n';
foreach($invoice->performances as $performance)
{
$play = $plays[$performance->play_id];
$thisAmount = 0;
switch($play->type)
{
case "tragedy":
$thisAmount = 40000;
if($performance->audience > 30)
{
$thisAmount += 1000 * ($performance->audience - 30);
}
break;
case "comedy":
$thisAmount = 30000;
if($performance->audience > 20)
{
$thisAmount += 10000 + 500 * ($performance->audience - 20);
}
$thisAmount += 300 * $performance->audience;
break;
default:
throw new \Error("Unknow type: $play->type");
}
$volumeCredits += max($performance->audience - 30, 0);
if($play->type == 'comedy')
{
$volumeCredits += floor($performance->audience / 5);
}
$thisFinalAmount = $thisAmount / 100;
$result = "$play->name: $thisFinalAmount ($performance->audience seats)\n";
$totalAmount += $thisAmount;
}
$finalTotal = ($totalAmount / 100);
$result .= "Amount owed is $finalTotal\n";
$result .= "You earned $volumeCredits credits\n";
return $result;
}
}