@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | if ($smb != null) |
| 28 | 28 | $this->smb = $smb->from(); |
| 29 | 29 | |
| 30 | - if (!empty($this->smb)) { |
|
| 30 | + if ( ! empty($this->smb)) { |
|
| 31 | 31 | // StateEnum::CURRENT_STATE => [ EventEnum::ON_EVENT => [ NEXT_STATE, ClosureOrFunctionsArray ] ], |
| 32 | 32 | foreach ($this->smb as $state => $transition) { |
| 33 | 33 | $this->addState($state); |
@@ -70,12 +70,12 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | $this->setCurrentStateIfThisIsInitialState($currentState); |
| 72 | 72 | |
| 73 | - if( $execAction === null ){ |
|
| 74 | - $this->sm[$currentState][$currentEvent] = [ self::NEXT_STATE => $nextState ]; |
|
| 73 | + if ($execAction === null) { |
|
| 74 | + $this->sm[$currentState][$currentEvent] = [self::NEXT_STATE => $nextState]; |
|
| 75 | 75 | } elseif (is_array($execAction)) { |
| 76 | 76 | $arrayActions = $execAction; |
| 77 | - $this->sm[$currentState][$currentEvent] = [ self::NEXT_STATE => $nextState ] + $arrayActions; |
|
| 78 | - } elseif($execAction instanceof \Closure) { |
|
| 77 | + $this->sm[$currentState][$currentEvent] = [self::NEXT_STATE => $nextState] + $arrayActions; |
|
| 78 | + } elseif ($execAction instanceof \Closure) { |
|
| 79 | 79 | $this->sm[$currentState][$currentEvent] = [ |
| 80 | 80 | self::NEXT_STATE => $nextState, |
| 81 | 81 | self::EXEC_ACTION => $execAction |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | $wasGuarded = $this->execGuard($transition); |
| 126 | 126 | |
| 127 | - if (!$wasGuarded) { |
|
| 127 | + if ( ! $wasGuarded) { |
|
| 128 | 128 | $this->execAction(self::EXEC_BEFORE, $transition); |
| 129 | 129 | $this->execAction(self::EXEC_ACTION, $transition); |
| 130 | 130 | $this->execAction(self::EXEC_AFTER, $transition); |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | private function execGuard($transition) |
| 149 | 149 | { |
| 150 | 150 | $wasGuarded = false; |
| 151 | - if( array_key_exists(self::EXEC_GUARD, $transition) ){ |
|
| 151 | + if (array_key_exists(self::EXEC_GUARD, $transition)) { |
|
| 152 | 152 | $guard = $transition[self::EXEC_GUARD]; |
| 153 | 153 | if ($guard) { |
| 154 | 154 | if (($guard)($this) === false) |
@@ -172,9 +172,9 @@ discard block |
||
| 172 | 172 | { |
| 173 | 173 | $this->argumentIsValidOrFail($event); |
| 174 | 174 | |
| 175 | - try{ |
|
| 175 | + try { |
|
| 176 | 176 | $this->eventMustExistOrFail($event); |
| 177 | - } catch(\InvalidArgumentException $e){ |
|
| 177 | + } catch (\InvalidArgumentException $e) { |
|
| 178 | 178 | return false; |
| 179 | 179 | } |
| 180 | 180 | |
@@ -237,31 +237,31 @@ discard block |
||
| 237 | 237 | |
| 238 | 238 | private function argumentIsNotNullOrFail($arg): void |
| 239 | 239 | { |
| 240 | - if( $arg === null ) |
|
| 240 | + if ($arg === null) |
|
| 241 | 241 | throw new \InvalidArgumentException("Null is not an valid argument"); |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | private function argumentIsNotBlankOrFail($arg): void |
| 245 | 245 | { |
| 246 | - if( trim($arg) === "" ) |
|
| 246 | + if (trim($arg) === "") |
|
| 247 | 247 | throw new \InvalidArgumentException("Blank is not an valid argument"); |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | private function eventMustExistOrFail($event) |
| 251 | 251 | { |
| 252 | - if( !( isset($this->sm[$this->currentState][$event]) ) ) |
|
| 252 | + if ( ! (isset($this->sm[$this->currentState][$event]))) |
|
| 253 | 253 | throw new \InvalidArgumentException("Unexpected event '{$event}' on '{$this->currentState}' state"); |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | private function stateMustExistOrFail($state) |
| 257 | 257 | { |
| 258 | - if( ! isset($this->sm[$state]) ) |
|
| 258 | + if ( ! isset($this->sm[$state])) |
|
| 259 | 259 | throw new \InvalidArgumentException("Event '{$this->currentEvent}' fired to unadded '{$state}' state"); |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | private function setCurrentStateIfThisIsInitialState($state): void |
| 263 | 263 | { |
| 264 | - if( $this->currentState == null){ |
|
| 264 | + if ($this->currentState == null) { |
|
| 265 | 265 | $this->currentState = $state; |
| 266 | 266 | } |
| 267 | 267 | } |
@@ -24,8 +24,9 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | public function __construct(StateMachineBuilder $smb = null) |
| 26 | 26 | { |
| 27 | - if ($smb != null) |
|
| 28 | - $this->smb = $smb->from(); |
|
| 27 | + if ($smb != null) { |
|
| 28 | + $this->smb = $smb->from(); |
|
| 29 | + } |
|
| 29 | 30 | |
| 30 | 31 | if (!empty($this->smb)) { |
| 31 | 32 | // StateEnum::CURRENT_STATE => [ EventEnum::ON_EVENT => [ NEXT_STATE, ClosureOrFunctionsArray ] ], |
@@ -151,8 +152,9 @@ discard block |
||
| 151 | 152 | if( array_key_exists(self::EXEC_GUARD, $transition) ){ |
| 152 | 153 | $guard = $transition[self::EXEC_GUARD]; |
| 153 | 154 | if ($guard) { |
| 154 | - if (($guard)($this) === false) |
|
| 155 | - $wasGuarded = true; |
|
| 155 | + if (($guard)($this) === false) { |
|
| 156 | + $wasGuarded = true; |
|
| 157 | + } |
|
| 156 | 158 | } |
| 157 | 159 | } |
| 158 | 160 | return $wasGuarded; |
@@ -237,26 +239,30 @@ discard block |
||
| 237 | 239 | |
| 238 | 240 | private function argumentIsNotNullOrFail($arg): void |
| 239 | 241 | { |
| 240 | - if( $arg === null ) |
|
| 241 | - throw new \InvalidArgumentException("Null is not an valid argument"); |
|
| 242 | + if( $arg === null ) { |
|
| 243 | + throw new \InvalidArgumentException("Null is not an valid argument"); |
|
| 244 | + } |
|
| 242 | 245 | } |
| 243 | 246 | |
| 244 | 247 | private function argumentIsNotBlankOrFail($arg): void |
| 245 | 248 | { |
| 246 | - if( trim($arg) === "" ) |
|
| 247 | - throw new \InvalidArgumentException("Blank is not an valid argument"); |
|
| 249 | + if( trim($arg) === "" ) { |
|
| 250 | + throw new \InvalidArgumentException("Blank is not an valid argument"); |
|
| 251 | + } |
|
| 248 | 252 | } |
| 249 | 253 | |
| 250 | 254 | private function eventMustExistOrFail($event) |
| 251 | 255 | { |
| 252 | - if( !( isset($this->sm[$this->currentState][$event]) ) ) |
|
| 253 | - throw new \InvalidArgumentException("Unexpected event '{$event}' on '{$this->currentState}' state"); |
|
| 256 | + if( !( isset($this->sm[$this->currentState][$event]) ) ) { |
|
| 257 | + throw new \InvalidArgumentException("Unexpected event '{$event}' on '{$this->currentState}' state"); |
|
| 258 | + } |
|
| 254 | 259 | } |
| 255 | 260 | |
| 256 | 261 | private function stateMustExistOrFail($state) |
| 257 | 262 | { |
| 258 | - if( ! isset($this->sm[$state]) ) |
|
| 259 | - throw new \InvalidArgumentException("Event '{$this->currentEvent}' fired to unadded '{$state}' state"); |
|
| 263 | + if( ! isset($this->sm[$state]) ) { |
|
| 264 | + throw new \InvalidArgumentException("Event '{$this->currentEvent}' fired to unadded '{$state}' state"); |
|
| 265 | + } |
|
| 260 | 266 | } |
| 261 | 267 | |
| 262 | 268 | private function setCurrentStateIfThisIsInitialState($state): void |