@@ -19,15 +19,15 @@ discard block |
||
19 | 19 | |
20 | 20 | public function __construct(StateMachineBuilder $smb = null) |
21 | 21 | { |
22 | - if( $smb != null ) |
|
22 | + if ($smb != null) |
|
23 | 23 | $sm = $smb->__invoke(); |
24 | 24 | |
25 | - if( ! empty($sm) ){ |
|
25 | + if ( ! empty($sm)) { |
|
26 | 26 | // StateEnum::CURRENT_STATE => [ EventEnum::ON_EVENT => [ StateEnum::NEXT_STATE_2, ActionClosureOrFunction ] ], |
27 | - foreach ($sm as $state => $transition){ |
|
27 | + foreach ($sm as $state => $transition) { |
|
28 | 28 | $this->addState($state); |
29 | 29 | foreach ($transition as $onEvent => $nextStateAndAction) { |
30 | - if( array_key_exists(self::EXEC_ACTION, $nextStateAndAction) ) { |
|
30 | + if (array_key_exists(self::EXEC_ACTION, $nextStateAndAction)) { |
|
31 | 31 | $this->addTransition($state, $onEvent, $nextStateAndAction[self::NEXT_STATE], $nextStateAndAction[self::EXEC_ACTION]); |
32 | 32 | } else { |
33 | 33 | $this->addTransition($state, $onEvent, $nextStateAndAction[self::NEXT_STATE]); |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | return $this; |
49 | 49 | } |
50 | 50 | |
51 | - public function addTransition($currentState, $currentEvent, $nextState, \Closure $execAction = null ) |
|
51 | + public function addTransition($currentState, $currentEvent, $nextState, \Closure $execAction = null) |
|
52 | 52 | { |
53 | 53 | $this->argumentIsValidOrFail($currentState); |
54 | 54 | $this->argumentIsValidOrFail($currentEvent); |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | return $this; |
64 | 64 | } |
65 | 65 | |
66 | - public function addCommonTransition($currentEvent, $nextState, \Closure $execAction = null ) |
|
66 | + public function addCommonTransition($currentEvent, $nextState, \Closure $execAction = null) |
|
67 | 67 | { |
68 | 68 | $this->argumentIsValidOrFail($currentEvent); |
69 | 69 | $this->argumentIsValidOrFail($nextState); |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | { |
84 | 84 | $this->argumentIsValidOrFail($event); |
85 | 85 | |
86 | - if( $this->transitionInProgress ){ |
|
86 | + if ($this->transitionInProgress) { |
|
87 | 87 | array_push($this->eventsQueued, $event); |
88 | 88 | return $this; |
89 | 89 | } |
@@ -100,11 +100,11 @@ discard block |
||
100 | 100 | $this->currentEvent = $event; |
101 | 101 | |
102 | 102 | $action = $transition[self::EXEC_ACTION]; |
103 | - if( $action ){ |
|
103 | + if ($action) { |
|
104 | 104 | ($action)($this); |
105 | 105 | } |
106 | 106 | |
107 | - if( $this->cancelTransition ){ |
|
107 | + if ($this->cancelTransition) { |
|
108 | 108 | $this->cancelTransition = false; |
109 | 109 | } else { |
110 | 110 | $this->currentState = $transition[self::NEXT_STATE]; |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | |
113 | 113 | $this->transitionInProgress = false; |
114 | 114 | $event = array_shift($this->eventsQueued); |
115 | - if( $event != null ){ |
|
115 | + if ($event != null) { |
|
116 | 116 | $this->fireEvent($event); |
117 | 117 | } |
118 | 118 | |
@@ -152,31 +152,31 @@ discard block |
||
152 | 152 | |
153 | 153 | private function argumentIsNotNullOrFail($arg): void |
154 | 154 | { |
155 | - if( $arg === null ) |
|
155 | + if ($arg === null) |
|
156 | 156 | throw new \InvalidArgumentException("Null is not an valid argument"); |
157 | 157 | } |
158 | 158 | |
159 | 159 | private function argumentIsNotBlankOrFail($arg): void |
160 | 160 | { |
161 | - if( trim($arg) === "" ) |
|
161 | + if (trim($arg) === "") |
|
162 | 162 | throw new \InvalidArgumentException("Blank is not an valid argument"); |
163 | 163 | } |
164 | 164 | |
165 | 165 | private function eventMustExistOrFail($event) |
166 | 166 | { |
167 | - if( !( isset($this->sm[$this->currentState][$event]) ) ) |
|
167 | + if ( ! (isset($this->sm[$this->currentState][$event]))) |
|
168 | 168 | throw new \InvalidArgumentException("Unexpected event {$event} on {$this->currentState} state"); |
169 | 169 | } |
170 | 170 | |
171 | 171 | private function stateMustExistOrFail($state) |
172 | 172 | { |
173 | - if( ! isset($this->sm[$state]) ) |
|
173 | + if ( ! isset($this->sm[$state])) |
|
174 | 174 | throw new \InvalidArgumentException("Event '{$this->currentEvent}' fired an unexpected '{$state}' state"); |
175 | 175 | } |
176 | 176 | |
177 | 177 | private function setCurrentStateIfThisIsInitialState($state): void |
178 | 178 | { |
179 | - if( $this->currentState == null){ |
|
179 | + if ($this->currentState == null) { |
|
180 | 180 | $this->currentState = $state; |
181 | 181 | } |
182 | 182 | } |
@@ -19,8 +19,9 @@ discard block |
||
19 | 19 | |
20 | 20 | public function __construct(StateMachineBuilder $smb = null) |
21 | 21 | { |
22 | - if( $smb != null ) |
|
23 | - $sm = $smb->__invoke(); |
|
22 | + if( $smb != null ) { |
|
23 | + $sm = $smb->__invoke(); |
|
24 | + } |
|
24 | 25 | |
25 | 26 | if( ! empty($sm) ){ |
26 | 27 | // StateEnum::CURRENT_STATE => [ EventEnum::ON_EVENT => [ StateEnum::NEXT_STATE_2, ActionClosureOrFunction ] ], |
@@ -152,26 +153,30 @@ discard block |
||
152 | 153 | |
153 | 154 | private function argumentIsNotNullOrFail($arg): void |
154 | 155 | { |
155 | - if( $arg === null ) |
|
156 | - throw new \InvalidArgumentException("Null is not an valid argument"); |
|
156 | + if( $arg === null ) { |
|
157 | + throw new \InvalidArgumentException("Null is not an valid argument"); |
|
158 | + } |
|
157 | 159 | } |
158 | 160 | |
159 | 161 | private function argumentIsNotBlankOrFail($arg): void |
160 | 162 | { |
161 | - if( trim($arg) === "" ) |
|
162 | - throw new \InvalidArgumentException("Blank is not an valid argument"); |
|
163 | + if( trim($arg) === "" ) { |
|
164 | + throw new \InvalidArgumentException("Blank is not an valid argument"); |
|
165 | + } |
|
163 | 166 | } |
164 | 167 | |
165 | 168 | private function eventMustExistOrFail($event) |
166 | 169 | { |
167 | - if( !( isset($this->sm[$this->currentState][$event]) ) ) |
|
168 | - throw new \InvalidArgumentException("Unexpected event {$event} on {$this->currentState} state"); |
|
170 | + if( !( isset($this->sm[$this->currentState][$event]) ) ) { |
|
171 | + throw new \InvalidArgumentException("Unexpected event {$event} on {$this->currentState} state"); |
|
172 | + } |
|
169 | 173 | } |
170 | 174 | |
171 | 175 | private function stateMustExistOrFail($state) |
172 | 176 | { |
173 | - if( ! isset($this->sm[$state]) ) |
|
174 | - throw new \InvalidArgumentException("Event '{$this->currentEvent}' fired an unexpected '{$state}' state"); |
|
177 | + if( ! isset($this->sm[$state]) ) { |
|
178 | + throw new \InvalidArgumentException("Event '{$this->currentEvent}' fired an unexpected '{$state}' state"); |
|
179 | + } |
|
175 | 180 | } |
176 | 181 | |
177 | 182 | private function setCurrentStateIfThisIsInitialState($state): void |