@@ -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 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 |
@@ -2,8 +2,8 @@ |
||
2 | 2 | |
3 | 3 | namespace DesignPattern\Behavioral\Mediator; |
4 | 4 | |
5 | -interface MediatorInterface |
|
6 | -{ |
|
5 | +interface MediatorInterface |
|
6 | +{ |
|
7 | 7 | public function sendRequest(); |
8 | 8 | |
9 | 9 | public function query(); |
@@ -2,15 +2,15 @@ |
||
2 | 2 | |
3 | 3 | namespace DesignPattern\Behavioral\Mediator; |
4 | 4 | |
5 | -class Consumer extends AbstractColleague |
|
6 | -{ |
|
7 | - public function request() |
|
8 | - { |
|
5 | +class Consumer extends AbstractColleague |
|
6 | +{ |
|
7 | + public function request() |
|
8 | + { |
|
9 | 9 | return $this->getMediator()->sendRequest(); |
10 | 10 | } |
11 | 11 | |
12 | - public function output($content) |
|
13 | - { |
|
12 | + public function output($content) |
|
13 | + { |
|
14 | 14 | return $content; |
15 | 15 | } |
16 | 16 | } |
@@ -2,8 +2,8 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace DesignPattern\Behavioral\Mediator; |
4 | 4 | |
5 | -class Mediator implements MediatorInterface |
|
6 | -{ |
|
5 | +class Mediator implements MediatorInterface |
|
6 | +{ |
|
7 | 7 | /** |
8 | 8 | * @var \DesignPattern\Behavioral\Mediator\Consumer |
9 | 9 | */ |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | * |
67 | 67 | * @return mixed |
68 | 68 | */ |
69 | - public function sendRequest() |
|
70 | - { |
|
69 | + public function sendRequest() |
|
70 | + { |
|
71 | 71 | return $this->server->response(); |
72 | 72 | } |
73 | 73 |
@@ -2,10 +2,10 @@ |
||
2 | 2 | |
3 | 3 | namespace DesignPattern\Behavioral\Mediator; |
4 | 4 | |
5 | -class Server extends AbstractColleague |
|
6 | -{ |
|
7 | - public function response() |
|
8 | - { |
|
5 | +class Server extends AbstractColleague |
|
6 | +{ |
|
7 | + public function response() |
|
8 | + { |
|
9 | 9 | $data = $this->getMediator()->query(); |
10 | 10 | |
11 | 11 | return $this->getMediator()->recvResponse(sprintf('Hello %s', $data)); |