-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSeason.php
More file actions
45 lines (37 loc) · 995 Bytes
/
Season.php
File metadata and controls
45 lines (37 loc) · 995 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace Slutsky\EnumExample;
use InvalidArgumentException;
class Season
{
public const SUMMER = 'summer';
public const AUTUMN = 'autumn';
public const WINTER = 'winter';
public const SPRING = 'spring';
private string $value;
public function __construct(string $value)
{
if (
self::SUMMER !== $value &&
self::AUTUMN !== $value &&
self::WINTER !== $value &&
self::SPRING !== $value
) {
throw new InvalidArgumentException(sprintf(
"Wrong season value. Awaited '%s', '%s', '%s' or '%s'.",
self::SUMMER,
self::AUTUMN,
self::WINTER,
self::SPRING
));
}
$this->value = $value;
}
public function __toString(): string
{
return $this->value;
}
public function equals(Season $season): bool
{
return $this->value === $season->value;
}
}