@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | if ($smb != null) |
| 27 | 27 | $this->smb = $smb->from(); |
| 28 | 28 | |
| 29 | - if (!empty($this->smb)) { |
|
| 29 | + if ( ! empty($this->smb)) { |
|
| 30 | 30 | // StateEnum::CURRENT_STATE => [ EventEnum::ON_EVENT => [ NEXT_STATE, ClosureOrFunctionsArray ] ], |
| 31 | 31 | foreach ($this->smb as $state => $transition) { |
| 32 | 32 | $this->addState($state); |
@@ -69,20 +69,20 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | $this->setCurrentStateIfThisIsInitialState($currentState); |
| 71 | 71 | |
| 72 | - if( $execAction === null ){ |
|
| 73 | - $this->sm[$currentState][$currentEvent] = [ self::NEXT_STATE => $nextState ]; |
|
| 72 | + if ($execAction === null) { |
|
| 73 | + $this->sm[$currentState][$currentEvent] = [self::NEXT_STATE => $nextState]; |
|
| 74 | 74 | } elseif (is_array($execAction)) { |
| 75 | - $this->sm[$currentState][$currentEvent] = [ self::NEXT_STATE => $nextState ]; |
|
| 75 | + $this->sm[$currentState][$currentEvent] = [self::NEXT_STATE => $nextState]; |
|
| 76 | 76 | $arrayActions = $execAction; |
| 77 | 77 | foreach ($arrayActions as $exec_action => $action) { |
| 78 | - if( in_array($exec_action, [self::EXEC_ACTION, self::EXEC_GUARD, self::EXEC_BEFORE, self::EXEC_AFTER], true) ){ |
|
| 79 | - if( $action === null ) |
|
| 78 | + if (in_array($exec_action, [self::EXEC_ACTION, self::EXEC_GUARD, self::EXEC_BEFORE, self::EXEC_AFTER], true)) { |
|
| 79 | + if ($action === null) |
|
| 80 | 80 | continue; |
| 81 | 81 | $this->argumentMustBeClosureOrFail($action); |
| 82 | 82 | } |
| 83 | 83 | $this->sm[$currentState][$currentEvent][$exec_action] = $action; |
| 84 | 84 | } |
| 85 | - } elseif($execAction instanceof \Closure) { |
|
| 85 | + } elseif ($execAction instanceof \Closure) { |
|
| 86 | 86 | $this->sm[$currentState][$currentEvent] = [ |
| 87 | 87 | self::NEXT_STATE => $nextState, |
| 88 | 88 | self::EXEC_ACTION => $execAction |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | |
| 133 | 133 | $wasGuarded = $this->execGuard($transition); |
| 134 | 134 | |
| 135 | - if (!$wasGuarded) { |
|
| 135 | + if ( ! $wasGuarded) { |
|
| 136 | 136 | $this->execAction(self::EXEC_BEFORE, $transition); |
| 137 | 137 | $this->execAction(self::EXEC_ACTION, $transition); |
| 138 | 138 | $this->execAction(self::EXEC_AFTER, $transition); |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | private function execGuard($transition): bool |
| 157 | 157 | { |
| 158 | 158 | $wasGuarded = false; |
| 159 | - if( array_key_exists(self::EXEC_GUARD, $transition) ){ |
|
| 159 | + if (array_key_exists(self::EXEC_GUARD, $transition)) { |
|
| 160 | 160 | $guard = $transition[self::EXEC_GUARD]; |
| 161 | 161 | if ($guard) { |
| 162 | 162 | if (($guard)($this) === false) |
@@ -180,9 +180,9 @@ discard block |
||
| 180 | 180 | { |
| 181 | 181 | $this->argumentIsValidOrFail($event); |
| 182 | 182 | |
| 183 | - try{ |
|
| 183 | + try { |
|
| 184 | 184 | $this->eventMustExistOrFail($event); |
| 185 | - } catch(\InvalidArgumentException $e){ |
|
| 185 | + } catch (\InvalidArgumentException $e) { |
|
| 186 | 186 | return false; |
| 187 | 187 | } |
| 188 | 188 | |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | |
| 240 | 240 | private function setCurrentStateIfThisIsInitialState($state): void |
| 241 | 241 | { |
| 242 | - if( $this->currentState == null) |
|
| 242 | + if ($this->currentState == null) |
|
| 243 | 243 | $this->currentState = $state; |
| 244 | 244 | } |
| 245 | 245 | |
@@ -251,31 +251,31 @@ discard block |
||
| 251 | 251 | |
| 252 | 252 | private function argumentIsNotNullOrFail($arg): void |
| 253 | 253 | { |
| 254 | - if( $arg === null ) |
|
| 254 | + if ($arg === null) |
|
| 255 | 255 | throw new \InvalidArgumentException("Null is not an valid argument"); |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | private function argumentIsNotBlankOrFail($arg): void |
| 259 | 259 | { |
| 260 | - if( trim($arg) === "" ) |
|
| 260 | + if (trim($arg) === "") |
|
| 261 | 261 | throw new \InvalidArgumentException("Blank is not an valid argument"); |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | private function eventMustExistOrFail($event) |
| 265 | 265 | { |
| 266 | - if( !( isset($this->sm[$this->currentState][$event]) ) ) |
|
| 266 | + if ( ! (isset($this->sm[$this->currentState][$event]))) |
|
| 267 | 267 | throw new \InvalidArgumentException("Unexpected event '{$event}' on '{$this->currentState}' state"); |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | private function stateMustExistOrFail($state) |
| 271 | 271 | { |
| 272 | - if( ! isset($this->sm[$state]) ) |
|
| 272 | + if ( ! isset($this->sm[$state])) |
|
| 273 | 273 | throw new \InvalidArgumentException("Event '{$this->currentEvent}' fired to unadded '{$state}' state"); |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | private function argumentMustBeClosureOrFail($action): void |
| 277 | 277 | { |
| 278 | - if( !($action instanceof \Closure) ) |
|
| 278 | + if ( ! ($action instanceof \Closure)) |
|
| 279 | 279 | throw new \InvalidArgumentException('execAction argument must be Closure or array'); |
| 280 | 280 | } |
| 281 | 281 | } |