1 | <?php |
||
29 | final class Direction implements ValueObjectInterface |
||
30 | { |
||
31 | const UP = 'up'; |
||
32 | const DOWN = 'down'; |
||
33 | |||
34 | /** @var string */ |
||
35 | private $direction; |
||
36 | |||
37 | /** |
||
38 | * Direction constructor. |
||
39 | * @param int|string $direction |
||
40 | * @throws InvalidArgumentException |
||
41 | */ |
||
42 | 37 | public function __construct($direction) |
|
55 | |||
56 | /** |
||
57 | * Returns whether the direction is up |
||
58 | * |
||
59 | * @return bool |
||
60 | */ |
||
61 | 47 | public function isUp() { |
|
64 | |||
65 | /** |
||
66 | * Returns whether the direction is down |
||
67 | * |
||
68 | * @return bool |
||
69 | */ |
||
70 | 15 | public function isDown() { |
|
73 | |||
74 | /** |
||
75 | * Returns the direction as string |
||
76 | * |
||
77 | * @return string |
||
78 | */ |
||
79 | 7 | public function getDirection() { |
|
82 | |||
83 | /** |
||
84 | * @inheritdoc |
||
85 | */ |
||
86 | 7 | public function isSameValueAs(ValueObjectInterface $object) |
|
87 | { |
||
88 | 7 | if (!$object instanceof Direction) { |
|
89 | 1 | return false; |
|
90 | } |
||
91 | |||
92 | 7 | return $this->isUp() == $object->isUp(); |
|
93 | } |
||
94 | |||
95 | /** |
||
96 | * Returns a string representation of the object. |
||
97 | * |
||
98 | * @return string |
||
99 | */ |
||
100 | 5 | public function __toString() |
|
104 | |||
105 | /** |
||
106 | * Returns an instance with direction UP |
||
107 | * |
||
108 | * @return static |
||
109 | */ |
||
110 | 29 | public static function up() |
|
114 | |||
115 | /** |
||
116 | * Returns an instance with direction DOWN |
||
117 | * |
||
118 | * @return static |
||
119 | */ |
||
120 | 14 | public static function down() |
|
124 | } |
||
125 |