@@ -23,8 +23,9 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | public function __construct(StateMachineBuilder $smb = null) |
| 25 | 25 | { |
| 26 | - if ($smb != null) |
|
| 27 | - $this->smb = $smb->from(); |
|
| 26 | + if ($smb != null) { |
|
| 27 | + $this->smb = $smb->from(); |
|
| 28 | + } |
|
| 28 | 29 | |
| 29 | 30 | if (!empty($this->smb)) { |
| 30 | 31 | // StateEnum::CURRENT_STATE => [ EventEnum::ON_EVENT => [ NEXT_STATE, ClosureOrFunctionsArray ] ], |
@@ -76,8 +77,9 @@ discard block |
||
| 76 | 77 | $arrayActions = $execAction; |
| 77 | 78 | foreach ($arrayActions as $exec_action => $action) { |
| 78 | 79 | if( in_array($exec_action, [self::EXEC_ACTION, self::EXEC_GUARD, self::EXEC_BEFORE, self::EXEC_AFTER], true) ){ |
| 79 | - if( $action === null ) |
|
| 80 | - continue; |
|
| 80 | + if( $action === null ) { |
|
| 81 | + continue; |
|
| 82 | + } |
|
| 81 | 83 | $this->argumentMustBeClosureOrFail($action); |
| 82 | 84 | } |
| 83 | 85 | $this->sm[$currentState][$currentEvent][$exec_action] = $action; |
@@ -159,8 +161,9 @@ discard block |
||
| 159 | 161 | if( array_key_exists(self::EXEC_GUARD, $transition) ){ |
| 160 | 162 | $guard = $transition[self::EXEC_GUARD]; |
| 161 | 163 | if ($guard) { |
| 162 | - if (($guard)($this) === false) |
|
| 163 | - $wasGuarded = true; |
|
| 164 | + if (($guard)($this) === false) { |
|
| 165 | + $wasGuarded = true; |
|
| 166 | + } |
|
| 164 | 167 | } |
| 165 | 168 | } |
| 166 | 169 | return $wasGuarded; |
@@ -239,8 +242,9 @@ discard block |
||
| 239 | 242 | |
| 240 | 243 | private function setCurrentStateIfThisIsInitialState($state): void |
| 241 | 244 | { |
| 242 | - if( $this->currentState == null) |
|
| 243 | - $this->currentState = $state; |
|
| 245 | + if( $this->currentState == null) { |
|
| 246 | + $this->currentState = $state; |
|
| 247 | + } |
|
| 244 | 248 | } |
| 245 | 249 | |
| 246 | 250 | private function argumentIsValidOrFail($arg): void |
@@ -251,31 +255,36 @@ discard block |
||
| 251 | 255 | |
| 252 | 256 | private function argumentIsNotNullOrFail($arg): void |
| 253 | 257 | { |
| 254 | - if( $arg === null ) |
|
| 255 | - throw new \InvalidArgumentException("Null is not an valid argument"); |
|
| 258 | + if( $arg === null ) { |
|
| 259 | + throw new \InvalidArgumentException("Null is not an valid argument"); |
|
| 260 | + } |
|
| 256 | 261 | } |
| 257 | 262 | |
| 258 | 263 | private function argumentIsNotBlankOrFail($arg): void |
| 259 | 264 | { |
| 260 | - if( trim($arg) === "" ) |
|
| 261 | - throw new \InvalidArgumentException("Blank is not an valid argument"); |
|
| 265 | + if( trim($arg) === "" ) { |
|
| 266 | + throw new \InvalidArgumentException("Blank is not an valid argument"); |
|
| 267 | + } |
|
| 262 | 268 | } |
| 263 | 269 | |
| 264 | 270 | private function eventMustExistOrFail($event) |
| 265 | 271 | { |
| 266 | - if( !( isset($this->sm[$this->currentState][$event]) ) ) |
|
| 267 | - throw new \InvalidArgumentException("Unexpected event '{$event}' on '{$this->currentState}' state"); |
|
| 272 | + if( !( isset($this->sm[$this->currentState][$event]) ) ) { |
|
| 273 | + throw new \InvalidArgumentException("Unexpected event '{$event}' on '{$this->currentState}' state"); |
|
| 274 | + } |
|
| 268 | 275 | } |
| 269 | 276 | |
| 270 | 277 | private function stateMustExistOrFail($state) |
| 271 | 278 | { |
| 272 | - if( ! isset($this->sm[$state]) ) |
|
| 273 | - throw new \InvalidArgumentException("Event '{$this->currentEvent}' fired to unadded '{$state}' state"); |
|
| 279 | + if( ! isset($this->sm[$state]) ) { |
|
| 280 | + throw new \InvalidArgumentException("Event '{$this->currentEvent}' fired to unadded '{$state}' state"); |
|
| 281 | + } |
|
| 274 | 282 | } |
| 275 | 283 | |
| 276 | 284 | private function argumentMustBeClosureOrFail($action): void |
| 277 | 285 | { |
| 278 | - if( !($action instanceof \Closure) ) |
|
| 279 | - throw new \InvalidArgumentException('execAction argument must be Closure or array'); |
|
| 286 | + if( !($action instanceof \Closure) ) { |
|
| 287 | + throw new \InvalidArgumentException('execAction argument must be Closure or array'); |
|
| 288 | + } |
|
| 280 | 289 | } |
| 281 | 290 | } |