You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
773 B
36 lines
773 B
<?php
|
|
interface SizeInterface {
|
|
public function getSize(): string;
|
|
}
|
|
|
|
enum Size: string implements SizeInterface {
|
|
case Small = 'small';
|
|
case Grande = 'grande';
|
|
|
|
public function getSize(): string {
|
|
return $this->value;
|
|
}
|
|
}
|
|
|
|
|
|
class Coffee {
|
|
public string $flavor {
|
|
get {
|
|
return $this->flavor . ' Spice';
|
|
}
|
|
set(string $value) {
|
|
if (strlen($value) > 16) throw new InvalidArgumentException('Input is too long');
|
|
$this->flavor = $value;
|
|
}
|
|
}
|
|
|
|
public function serve(SizeInterface $size): void {
|
|
echo "\r\nServing a {$size->getSize()} coffee.\n";
|
|
}
|
|
}
|
|
|
|
$coffee = new Coffee();
|
|
$coffee->flavor = 'Pumpkin';
|
|
echo $coffee->flavor;
|
|
|
|
$coffee->serve(Size::Grande);
|
|
|