@@ -4,25 +4,25 @@ |
||
4 | 4 | |
5 | 5 | namespace DesignPattern\Behavioral\State; |
6 | 6 | |
7 | -class Order |
|
8 | -{ |
|
7 | +class Order |
|
8 | +{ |
|
9 | 9 | /** |
10 | 10 | * @var \DesignPattern\Behavioral\State\StateInterface|null |
11 | 11 | */ |
12 | 12 | private ?StateInterface $state; |
13 | 13 | |
14 | - public function cancel() |
|
15 | - { |
|
14 | + public function cancel() |
|
15 | + { |
|
16 | 16 | return $this->state->toCancel($this); |
17 | 17 | } |
18 | 18 | |
19 | - public function pay() |
|
20 | - { |
|
19 | + public function pay() |
|
20 | + { |
|
21 | 21 | return $this->state->toPay($this); |
22 | 22 | } |
23 | 23 | |
24 | - public function dispatch() |
|
25 | - { |
|
24 | + public function dispatch() |
|
25 | + { |
|
26 | 26 | return $this->state->toDispatch($this); |
27 | 27 | } |
28 | 28 |
@@ -4,8 +4,8 @@ discard block |
||
4 | 4 | |
5 | 5 | namespace DesignPattern\Behavioral\State; |
6 | 6 | |
7 | -class Pay extends AbstractState |
|
8 | -{ |
|
7 | +class Pay extends AbstractState |
|
8 | +{ |
|
9 | 9 | /** |
10 | 10 | * @param \DesignPattern\Behavioral\State\Order $order |
11 | 11 | * |
@@ -23,8 +23,8 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @throws \LogicException |
25 | 25 | */ |
26 | - public function toDispatch(Order $order) |
|
27 | - { |
|
26 | + public function toDispatch(Order $order) |
|
27 | + { |
|
28 | 28 | throw new \LogicException('The order has to be paid before processing dispatch.'); |
29 | 29 | } |
30 | 30 | } |
@@ -4,8 +4,8 @@ discard block |
||
4 | 4 | |
5 | 5 | namespace DesignPattern\Behavioral\State; |
6 | 6 | |
7 | -abstract class AbstractState implements StateInterface |
|
8 | -{ |
|
7 | +abstract class AbstractState implements StateInterface |
|
8 | +{ |
|
9 | 9 | /** |
10 | 10 | * To cancel order. |
11 | 11 | * |
@@ -13,8 +13,8 @@ discard block |
||
13 | 13 | * |
14 | 14 | * @return mixed |
15 | 15 | */ |
16 | - public function toCancel(Order $order) |
|
17 | - { |
|
16 | + public function toCancel(Order $order) |
|
17 | + { |
|
18 | 18 | $order->setState(new Cancel()); |
19 | 19 | |
20 | 20 | return true; |
@@ -4,8 +4,8 @@ discard block |
||
4 | 4 | |
5 | 5 | namespace DesignPattern\Behavioral\State; |
6 | 6 | |
7 | -class Dispatch extends AbstractState |
|
8 | -{ |
|
7 | +class Dispatch extends AbstractState |
|
8 | +{ |
|
9 | 9 | /** |
10 | 10 | * To pay. |
11 | 11 | * |
@@ -13,8 +13,8 @@ discard block |
||
13 | 13 | * |
14 | 14 | * @throws \LogicException |
15 | 15 | */ |
16 | - public function toPay(Order $order) |
|
17 | - { |
|
16 | + public function toPay(Order $order) |
|
17 | + { |
|
18 | 18 | throw new \LogicException('Already paid.'); |
19 | 19 | } |
20 | 20 | |
@@ -25,8 +25,8 @@ discard block |
||
25 | 25 | * |
26 | 26 | * @throws \LogicException |
27 | 27 | */ |
28 | - public function toDispatch(Order $order) |
|
29 | - { |
|
28 | + public function toDispatch(Order $order) |
|
29 | + { |
|
30 | 30 | throw new \LogicException('Already dispatched.'); |
31 | 31 | } |
32 | 32 | } |
@@ -4,8 +4,8 @@ discard block |
||
4 | 4 | |
5 | 5 | namespace DesignPattern\Behavioral\State; |
6 | 6 | |
7 | -class Cancel extends AbstractState |
|
8 | -{ |
|
7 | +class Cancel extends AbstractState |
|
8 | +{ |
|
9 | 9 | public const ORDER_CANCEL = 1; |
10 | 10 | public const ORDER_PAY = 2; |
11 | 11 | public const ORDER_DISPATCH = 3; |
@@ -15,8 +15,8 @@ discard block |
||
15 | 15 | * |
16 | 16 | * @throws \LogicException |
17 | 17 | */ |
18 | - public function toCancel(Order $order) |
|
19 | - { |
|
18 | + public function toCancel(Order $order) |
|
19 | + { |
|
20 | 20 | throw new \LogicException('Already cancelled.', self::ORDER_CANCEL); |
21 | 21 | } |
22 | 22 | |
@@ -25,8 +25,8 @@ discard block |
||
25 | 25 | * |
26 | 26 | * @throws \LogicException |
27 | 27 | */ |
28 | - public function toPay(Order $order) |
|
29 | - { |
|
28 | + public function toPay(Order $order) |
|
29 | + { |
|
30 | 30 | throw new \LogicException('Order cancelled.', self::ORDER_PAY); |
31 | 31 | } |
32 | 32 | |
@@ -35,8 +35,8 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @throws \LogicException |
37 | 37 | */ |
38 | - public function toDispatch(Order $order) |
|
39 | - { |
|
38 | + public function toDispatch(Order $order) |
|
39 | + { |
|
40 | 40 | throw new \LogicException('Order cancelled.', self::ORDER_DISPATCH); |
41 | 41 | } |
42 | 42 | } |
@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | namespace DesignPattern\Behavioral\State; |
6 | 6 | |
7 | -interface StateInterface |
|
8 | -{ |
|
7 | +interface StateInterface |
|
8 | +{ |
|
9 | 9 | /** |
10 | 10 | * Order cancel. |
11 | 11 | * |
@@ -4,8 +4,8 @@ discard block |
||
4 | 4 | |
5 | 5 | namespace DesignPattern\Behavioral\Visitor; |
6 | 6 | |
7 | -class User implements RoleInterface |
|
8 | -{ |
|
7 | +class User implements RoleInterface |
|
8 | +{ |
|
9 | 9 | /** |
10 | 10 | * @var string |
11 | 11 | */ |
@@ -16,8 +16,8 @@ discard block |
||
16 | 16 | * |
17 | 17 | * @param string $name |
18 | 18 | */ |
19 | - public function __construct(string $name) |
|
20 | - { |
|
19 | + public function __construct(string $name) |
|
20 | + { |
|
21 | 21 | $this->name = $name; |
22 | 22 | } |
23 | 23 | |
@@ -36,8 +36,8 @@ discard block |
||
36 | 36 | * |
37 | 37 | * @return mixed|void |
38 | 38 | */ |
39 | - public function allow(VisitorInterface $visitor) |
|
40 | - { |
|
39 | + public function allow(VisitorInterface $visitor) |
|
40 | + { |
|
41 | 41 | $visitor->visitUser($this); |
42 | 42 | } |
43 | 43 | } |
@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | namespace DesignPattern\Behavioral\Visitor; |
6 | 6 | |
7 | -interface VisitorInterface |
|
8 | -{ |
|
7 | +interface VisitorInterface |
|
8 | +{ |
|
9 | 9 | /** |
10 | 10 | * @param \DesignPattern\Behavioral\Visitor\User $user |
11 | 11 | * |
@@ -4,8 +4,8 @@ discard block |
||
4 | 4 | |
5 | 5 | namespace DesignPattern\Behavioral\Visitor; |
6 | 6 | |
7 | -class RoleVisitor implements VisitorInterface |
|
8 | -{ |
|
7 | +class RoleVisitor implements VisitorInterface |
|
8 | +{ |
|
9 | 9 | /** |
10 | 10 | * @var \DesignPattern\Behavioral\Visitor\RoleInterface[] |
11 | 11 | */ |
@@ -16,8 +16,8 @@ discard block |
||
16 | 16 | * |
17 | 17 | * @return mixed|void |
18 | 18 | */ |
19 | - public function visitUser(User $user) |
|
20 | - { |
|
19 | + public function visitUser(User $user) |
|
20 | + { |
|
21 | 21 | $this->roles[] = $user; |
22 | 22 | } |
23 | 23 | |
@@ -26,8 +26,8 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @return mixed|void |
28 | 28 | */ |
29 | - public function visitGroup(Group $group) |
|
30 | - { |
|
29 | + public function visitGroup(Group $group) |
|
30 | + { |
|
31 | 31 | $this->roles[] = $group; |
32 | 32 | } |
33 | 33 |