@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | if ($smb != null) |
24 | 24 | $this->smb = $smb->from(); |
25 | 25 | |
26 | - if (!empty($this->smb)) { |
|
26 | + if ( ! empty($this->smb)) { |
|
27 | 27 | // StateEnum::CURRENT_STATE => [ EventEnum::ON_EVENT => [ NEXT_STATE, ClosureOrFunctionsArray ] ], |
28 | 28 | foreach ($this->smb as $state => $transition) { |
29 | 29 | $this->addState($state); |
@@ -66,20 +66,20 @@ discard block |
||
66 | 66 | |
67 | 67 | $this->setCurrentStateIfThisIsInitialState($currentState); |
68 | 68 | |
69 | - if( $execAction === null ){ |
|
70 | - $this->sm[$currentState][$currentEvent] = [ self::$NEXT_STATE => $nextState ]; |
|
69 | + if ($execAction === null) { |
|
70 | + $this->sm[$currentState][$currentEvent] = [self::$NEXT_STATE => $nextState]; |
|
71 | 71 | } elseif (is_array($execAction)) { |
72 | - $this->sm[$currentState][$currentEvent] = [ self::$NEXT_STATE => $nextState ]; |
|
72 | + $this->sm[$currentState][$currentEvent] = [self::$NEXT_STATE => $nextState]; |
|
73 | 73 | $arrayActions = $execAction; |
74 | 74 | foreach ($arrayActions as $exec_action => $action) { |
75 | - if( $this->in_actions_key($exec_action) ){ |
|
76 | - if( $action === null ) |
|
75 | + if ($this->in_actions_key($exec_action)) { |
|
76 | + if ($action === null) |
|
77 | 77 | continue; |
78 | 78 | $this->argumentMustBeClosureOrFail($action); |
79 | 79 | } |
80 | 80 | $this->sm[$currentState][$currentEvent][$exec_action] = $action; |
81 | 81 | } |
82 | - } elseif($execAction instanceof \Closure) { |
|
82 | + } elseif ($execAction instanceof \Closure) { |
|
83 | 83 | $this->sm[$currentState][$currentEvent] = [ |
84 | 84 | self::$NEXT_STATE => $nextState, |
85 | 85 | self::$EXEC_ACTION => $execAction |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | |
130 | 130 | $wasGuarded = $this->execGuard($transition); |
131 | 131 | |
132 | - if (!$wasGuarded) { |
|
132 | + if ( ! $wasGuarded) { |
|
133 | 133 | $this->execAction(self::$EXEC_BEFORE, $transition); |
134 | 134 | $this->execAction(self::$EXEC_ACTION, $transition); |
135 | 135 | $this->execAction(self::$EXEC_AFTER, $transition); |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | private function execGuard($transition): bool |
154 | 154 | { |
155 | 155 | $wasGuarded = false; |
156 | - if( array_key_exists(self::$EXEC_GUARD, $transition) ){ |
|
156 | + if (array_key_exists(self::$EXEC_GUARD, $transition)) { |
|
157 | 157 | $guard = $transition[self::$EXEC_GUARD]; |
158 | 158 | if ($guard) { |
159 | 159 | if (($guard)($this) === false) |
@@ -177,9 +177,9 @@ discard block |
||
177 | 177 | { |
178 | 178 | $this->argumentIsValidOrFail($event); |
179 | 179 | |
180 | - try{ |
|
180 | + try { |
|
181 | 181 | $this->eventMustExistOrFail($event); |
182 | - } catch(\InvalidArgumentException $e){ |
|
182 | + } catch (\InvalidArgumentException $e) { |
|
183 | 183 | return false; |
184 | 184 | } |
185 | 185 | |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | |
265 | 265 | private function setCurrentStateIfThisIsInitialState($state): void |
266 | 266 | { |
267 | - if( $this->currentState == null) |
|
267 | + if ($this->currentState == null) |
|
268 | 268 | $this->currentState = $state; |
269 | 269 | } |
270 | 270 | |
@@ -276,31 +276,31 @@ discard block |
||
276 | 276 | |
277 | 277 | private function argumentIsNotNullOrFail($arg): void |
278 | 278 | { |
279 | - if( $arg === null ) |
|
279 | + if ($arg === null) |
|
280 | 280 | throw new \InvalidArgumentException("Null is not an valid argument"); |
281 | 281 | } |
282 | 282 | |
283 | 283 | private function argumentIsNotBlankOrFail($arg): void |
284 | 284 | { |
285 | - if( trim($arg) === "" ) |
|
285 | + if (trim($arg) === "") |
|
286 | 286 | throw new \InvalidArgumentException("Blank is not an valid argument"); |
287 | 287 | } |
288 | 288 | |
289 | 289 | private function eventMustExistOrFail($event) |
290 | 290 | { |
291 | - if( !( isset($this->sm[$this->currentState][$event]) ) ) |
|
291 | + if ( ! (isset($this->sm[$this->currentState][$event]))) |
|
292 | 292 | throw new \InvalidArgumentException("Unexpected event '{$event}' on '{$this->currentState}' state"); |
293 | 293 | } |
294 | 294 | |
295 | 295 | private function stateMustExistOrFail($state) |
296 | 296 | { |
297 | - if( ! isset($this->sm[$state]) ) |
|
297 | + if ( ! isset($this->sm[$state])) |
|
298 | 298 | throw new \InvalidArgumentException("Event '{$this->currentEvent}' fired to unadded '{$state}' state"); |
299 | 299 | } |
300 | 300 | |
301 | 301 | private function argumentMustBeClosureOrFail($action): void |
302 | 302 | { |
303 | - if( !($action instanceof \Closure) ) |
|
303 | + if ( ! ($action instanceof \Closure)) |
|
304 | 304 | throw new \InvalidArgumentException('execAction argument must be Closure or array'); |
305 | 305 | } |
306 | 306 | } |
@@ -20,8 +20,9 @@ discard block |
||
20 | 20 | |
21 | 21 | public function __construct(StateMachineBuilder $smb = null) |
22 | 22 | { |
23 | - if ($smb != null) |
|
24 | - $this->smb = $smb->from(); |
|
23 | + if ($smb != null) { |
|
24 | + $this->smb = $smb->from(); |
|
25 | + } |
|
25 | 26 | |
26 | 27 | if (!empty($this->smb)) { |
27 | 28 | // StateEnum::CURRENT_STATE => [ EventEnum::ON_EVENT => [ NEXT_STATE, ClosureOrFunctionsArray ] ], |
@@ -73,8 +74,9 @@ discard block |
||
73 | 74 | $arrayActions = $execAction; |
74 | 75 | foreach ($arrayActions as $exec_action => $action) { |
75 | 76 | if( $this->in_actions_key($exec_action) ){ |
76 | - if( $action === null ) |
|
77 | - continue; |
|
77 | + if( $action === null ) { |
|
78 | + continue; |
|
79 | + } |
|
78 | 80 | $this->argumentMustBeClosureOrFail($action); |
79 | 81 | } |
80 | 82 | $this->sm[$currentState][$currentEvent][$exec_action] = $action; |
@@ -156,8 +158,9 @@ discard block |
||
156 | 158 | if( array_key_exists(self::$EXEC_GUARD, $transition) ){ |
157 | 159 | $guard = $transition[self::$EXEC_GUARD]; |
158 | 160 | if ($guard) { |
159 | - if (($guard)($this) === false) |
|
160 | - $wasGuarded = true; |
|
161 | + if (($guard)($this) === false) { |
|
162 | + $wasGuarded = true; |
|
163 | + } |
|
161 | 164 | } |
162 | 165 | } |
163 | 166 | return $wasGuarded; |
@@ -207,8 +210,9 @@ discard block |
||
207 | 210 | |
208 | 211 | $data_out = []; |
209 | 212 | foreach ($data as $value) { |
210 | - if ($this->in_actions_key($value)) |
|
211 | - continue; |
|
213 | + if ($this->in_actions_key($value)) { |
|
214 | + continue; |
|
215 | + } |
|
212 | 216 | $data_out[$value] = $this->sm[$this->currentState][$this->currentEvent][$value]; |
213 | 217 | } |
214 | 218 | |
@@ -264,8 +268,9 @@ discard block |
||
264 | 268 | |
265 | 269 | private function setCurrentStateIfThisIsInitialState($state): void |
266 | 270 | { |
267 | - if( $this->currentState == null) |
|
268 | - $this->currentState = $state; |
|
271 | + if( $this->currentState == null) { |
|
272 | + $this->currentState = $state; |
|
273 | + } |
|
269 | 274 | } |
270 | 275 | |
271 | 276 | private function argumentIsValidOrFail($arg): void |
@@ -276,31 +281,36 @@ discard block |
||
276 | 281 | |
277 | 282 | private function argumentIsNotNullOrFail($arg): void |
278 | 283 | { |
279 | - if( $arg === null ) |
|
280 | - throw new \InvalidArgumentException("Null is not an valid argument"); |
|
284 | + if( $arg === null ) { |
|
285 | + throw new \InvalidArgumentException("Null is not an valid argument"); |
|
286 | + } |
|
281 | 287 | } |
282 | 288 | |
283 | 289 | private function argumentIsNotBlankOrFail($arg): void |
284 | 290 | { |
285 | - if( trim($arg) === "" ) |
|
286 | - throw new \InvalidArgumentException("Blank is not an valid argument"); |
|
291 | + if( trim($arg) === "" ) { |
|
292 | + throw new \InvalidArgumentException("Blank is not an valid argument"); |
|
293 | + } |
|
287 | 294 | } |
288 | 295 | |
289 | 296 | private function eventMustExistOrFail($event) |
290 | 297 | { |
291 | - if( !( isset($this->sm[$this->currentState][$event]) ) ) |
|
292 | - throw new \InvalidArgumentException("Unexpected event '{$event}' on '{$this->currentState}' state"); |
|
298 | + if( !( isset($this->sm[$this->currentState][$event]) ) ) { |
|
299 | + throw new \InvalidArgumentException("Unexpected event '{$event}' on '{$this->currentState}' state"); |
|
300 | + } |
|
293 | 301 | } |
294 | 302 | |
295 | 303 | private function stateMustExistOrFail($state) |
296 | 304 | { |
297 | - if( ! isset($this->sm[$state]) ) |
|
298 | - throw new \InvalidArgumentException("Event '{$this->currentEvent}' fired to unadded '{$state}' state"); |
|
305 | + if( ! isset($this->sm[$state]) ) { |
|
306 | + throw new \InvalidArgumentException("Event '{$this->currentEvent}' fired to unadded '{$state}' state"); |
|
307 | + } |
|
299 | 308 | } |
300 | 309 | |
301 | 310 | private function argumentMustBeClosureOrFail($action): void |
302 | 311 | { |
303 | - if( !($action instanceof \Closure) ) |
|
304 | - throw new \InvalidArgumentException('execAction argument must be Closure or array'); |
|
312 | + if( !($action instanceof \Closure) ) { |
|
313 | + throw new \InvalidArgumentException('execAction argument must be Closure or array'); |
|
314 | + } |
|
305 | 315 | } |
306 | 316 | } |