mirror of
https://github.com/ysoftdevs/Theatrical-Players-Refactoring-Kata.git
synced 2026-05-05 15:34:36 +02:00
Add PHP version of kata
This commit is contained in:
16
php/src/Invoice.php
Normal file
16
php/src/Invoice.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Theatrical;
|
||||
|
||||
class Invoice
|
||||
{
|
||||
public string $customer;
|
||||
public array $performances;
|
||||
|
||||
public function __construct($customer, $performances)
|
||||
{
|
||||
$this->customer = $customer;
|
||||
$this->performances = $performances;
|
||||
}
|
||||
|
||||
}
|
||||
15
php/src/Performance.php
Normal file
15
php/src/Performance.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Theatrical;
|
||||
|
||||
class Performance
|
||||
{
|
||||
public string $play_id;
|
||||
public int $audience;
|
||||
|
||||
public function __construct($play_id, $audience)
|
||||
{
|
||||
$this->play_id = $play_id;
|
||||
$this->audience = $audience;
|
||||
}
|
||||
}
|
||||
20
php/src/Play.php
Normal file
20
php/src/Play.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Theatrical;
|
||||
|
||||
class Play
|
||||
{
|
||||
public string $name;
|
||||
public string $type;
|
||||
|
||||
public function __construct($name, $type)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return (string) $this->name . ' : ' . $this->type;
|
||||
}
|
||||
}
|
||||
63
php/src/StatementPrinter.php
Normal file
63
php/src/StatementPrinter.php
Normal 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;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user