@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - public function to(){ |
|
| 42 | + public function to(){ |
|
| 43 | 43 | // TODO: pendig of implementation |
| 44 | 44 | /* |
| 45 | 45 | if( $this->smb == null ) |
@@ -61,10 +61,10 @@ discard block |
||
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | public function addTransition($currentState, $currentEvent, $nextState, |
| 64 | - /*\Closure|array*/ $execAction = null, |
|
| 65 | - \Closure $execGuard = null, |
|
| 66 | - \Closure $execBefore = null, |
|
| 67 | - \Closure $execAfter = null) |
|
| 64 | + /*\Closure|array*/ $execAction = null, |
|
| 65 | + \Closure $execGuard = null, |
|
| 66 | + \Closure $execBefore = null, |
|
| 67 | + \Closure $execAfter = null) |
|
| 68 | 68 | { |
| 69 | 69 | $this->argumentIsValidOrFail($currentState); |
| 70 | 70 | $this->argumentIsValidOrFail($currentEvent); |
@@ -23,12 +23,12 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | public function __construct(StateMachineBuilder $smb = null) |
| 25 | 25 | { |
| 26 | - if( $smb != null ) |
|
| 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, ActionClosureOrFunction ] ], |
| 31 | - foreach ($this->smb as $state => $transition){ |
|
| 31 | + foreach ($this->smb as $state => $transition) { |
|
| 32 | 32 | $this->addState($state); |
| 33 | 33 | foreach ($transition as $onEvent => $nextStateAndAction) { |
| 34 | 34 | $this->addTransition($state, $onEvent, |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - public function to(){ |
|
| 42 | + public function to() { |
|
| 43 | 43 | // TODO: pendig of implementation |
| 44 | 44 | /* |
| 45 | 45 | if( $this->smb == null ) |
@@ -72,8 +72,8 @@ discard block |
||
| 72 | 72 | |
| 73 | 73 | $this->setCurrentStateIfThisIsInitialState($currentState); |
| 74 | 74 | |
| 75 | - if( is_array($execAction) ){ |
|
| 76 | - $this->sm[$currentState][$currentEvent] = [ self::NEXT_STATE => $nextState ]; |
|
| 75 | + if (is_array($execAction)) { |
|
| 76 | + $this->sm[$currentState][$currentEvent] = [self::NEXT_STATE => $nextState]; |
|
| 77 | 77 | $arrayActions = $execAction; |
| 78 | 78 | foreach ($arrayActions as $key => $value) { |
| 79 | 79 | $this->sm[$currentState][$currentEvent][$key] = $value; |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | $this->stateMustExistOrFail($this->nextState); |
| 133 | 133 | |
| 134 | 134 | $wasGuarded = false; |
| 135 | - if( array_key_exists(self::EXEC_GUARD, $transition) ){ |
|
| 135 | + if (array_key_exists(self::EXEC_GUARD, $transition)) { |
|
| 136 | 136 | $guard = $transition[self::EXEC_GUARD]; |
| 137 | 137 | if ($guard) { |
| 138 | 138 | if (($guard)($this) === false) |
@@ -140,19 +140,19 @@ discard block |
||
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | 142 | if ( ! $wasGuarded) { |
| 143 | - if( array_key_exists(self::EXEC_BEFORE, $transition) ) { |
|
| 143 | + if (array_key_exists(self::EXEC_BEFORE, $transition)) { |
|
| 144 | 144 | $before = $transition[self::EXEC_BEFORE]; |
| 145 | 145 | if ($before) { |
| 146 | 146 | ($before)($this); |
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | - if( array_key_exists(self::EXEC_ACTION, $transition) ) { |
|
| 149 | + if (array_key_exists(self::EXEC_ACTION, $transition)) { |
|
| 150 | 150 | $action = $transition[self::EXEC_ACTION]; |
| 151 | 151 | if ($action) { |
| 152 | 152 | ($action)($this); |
| 153 | 153 | } |
| 154 | 154 | } |
| 155 | - if( array_key_exists(self::EXEC_AFTER, $transition) ) { |
|
| 155 | + if (array_key_exists(self::EXEC_AFTER, $transition)) { |
|
| 156 | 156 | $after = $transition[self::EXEC_AFTER]; |
| 157 | 157 | if ($after) { |
| 158 | 158 | ($after)($this); |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - if( $this->cancelTransition || $wasGuarded ){ |
|
| 163 | + if ($this->cancelTransition || $wasGuarded) { |
|
| 164 | 164 | $this->cancelTransition = false; |
| 165 | 165 | } else { |
| 166 | 166 | $this->currentState = $transition[self::NEXT_STATE]; |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | |
| 169 | 169 | $this->transitionInProgress = false; |
| 170 | 170 | $event = array_shift($this->eventsQueued); |
| 171 | - if( $event != null ){ |
|
| 171 | + if ($event != null) { |
|
| 172 | 172 | $this->fireEvent($event); |
| 173 | 173 | } |
| 174 | 174 | |
@@ -179,9 +179,9 @@ discard block |
||
| 179 | 179 | { |
| 180 | 180 | $this->argumentIsValidOrFail($event); |
| 181 | 181 | |
| 182 | - try{ |
|
| 182 | + try { |
|
| 183 | 183 | $this->eventMustExistOrFail($event); |
| 184 | - } catch(\InvalidArgumentException $e){ |
|
| 184 | + } catch (\InvalidArgumentException $e) { |
|
| 185 | 185 | return false; |
| 186 | 186 | } |
| 187 | 187 | |
@@ -192,14 +192,14 @@ discard block |
||
| 192 | 192 | |
| 193 | 193 | $this->stateMustExistOrFail($this->nextState); |
| 194 | 194 | |
| 195 | - if( ! array_key_exists(self::EXEC_GUARD, $transition)){ |
|
| 195 | + if ( ! array_key_exists(self::EXEC_GUARD, $transition)) { |
|
| 196 | 196 | return true; |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | $can = true; |
| 200 | 200 | $guard = $transition[self::EXEC_GUARD]; |
| 201 | - if( $guard ){ |
|
| 202 | - if( ($guard)($this) === false ) |
|
| 201 | + if ($guard) { |
|
| 202 | + if (($guard)($this) === false) |
|
| 203 | 203 | $can = false; |
| 204 | 204 | } |
| 205 | 205 | return $can; |
@@ -247,31 +247,31 @@ discard block |
||
| 247 | 247 | |
| 248 | 248 | private function argumentIsNotNullOrFail($arg): void |
| 249 | 249 | { |
| 250 | - if( $arg === null ) |
|
| 250 | + if ($arg === null) |
|
| 251 | 251 | throw new \InvalidArgumentException("Null is not an valid argument"); |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | private function argumentIsNotBlankOrFail($arg): void |
| 255 | 255 | { |
| 256 | - if( trim($arg) === "" ) |
|
| 256 | + if (trim($arg) === "") |
|
| 257 | 257 | throw new \InvalidArgumentException("Blank is not an valid argument"); |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | private function eventMustExistOrFail($event) |
| 261 | 261 | { |
| 262 | - if( !( isset($this->sm[$this->currentState][$event]) ) ) |
|
| 262 | + if ( ! (isset($this->sm[$this->currentState][$event]))) |
|
| 263 | 263 | throw new \InvalidArgumentException("Unexpected event '{$event}' on '{$this->currentState}' state"); |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | private function stateMustExistOrFail($state) |
| 267 | 267 | { |
| 268 | - if( ! isset($this->sm[$state]) ) |
|
| 268 | + if ( ! isset($this->sm[$state])) |
|
| 269 | 269 | throw new \InvalidArgumentException("Event '{$this->currentEvent}' fired to unadded '{$state}' state"); |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | private function setCurrentStateIfThisIsInitialState($state): void |
| 273 | 273 | { |
| 274 | - if( $this->currentState == null){ |
|
| 274 | + if ($this->currentState == null) { |
|
| 275 | 275 | $this->currentState = $state; |
| 276 | 276 | } |
| 277 | 277 | } |
@@ -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, ActionClosureOrFunction ] ], |
@@ -135,8 +136,9 @@ discard block |
||
| 135 | 136 | if( array_key_exists(self::EXEC_GUARD, $transition) ){ |
| 136 | 137 | $guard = $transition[self::EXEC_GUARD]; |
| 137 | 138 | if ($guard) { |
| 138 | - if (($guard)($this) === false) |
|
| 139 | - $wasGuarded = true; |
|
| 139 | + if (($guard)($this) === false) { |
|
| 140 | + $wasGuarded = true; |
|
| 141 | + } |
|
| 140 | 142 | } |
| 141 | 143 | } |
| 142 | 144 | if ( ! $wasGuarded) { |
@@ -199,8 +201,9 @@ discard block |
||
| 199 | 201 | $can = true; |
| 200 | 202 | $guard = $transition[self::EXEC_GUARD]; |
| 201 | 203 | if( $guard ){ |
| 202 | - if( ($guard)($this) === false ) |
|
| 203 | - $can = false; |
|
| 204 | + if( ($guard)($this) === false ) { |
|
| 205 | + $can = false; |
|
| 206 | + } |
|
| 204 | 207 | } |
| 205 | 208 | return $can; |
| 206 | 209 | } |
@@ -247,26 +250,30 @@ discard block |
||
| 247 | 250 | |
| 248 | 251 | private function argumentIsNotNullOrFail($arg): void |
| 249 | 252 | { |
| 250 | - if( $arg === null ) |
|
| 251 | - throw new \InvalidArgumentException("Null is not an valid argument"); |
|
| 253 | + if( $arg === null ) { |
|
| 254 | + throw new \InvalidArgumentException("Null is not an valid argument"); |
|
| 255 | + } |
|
| 252 | 256 | } |
| 253 | 257 | |
| 254 | 258 | private function argumentIsNotBlankOrFail($arg): void |
| 255 | 259 | { |
| 256 | - if( trim($arg) === "" ) |
|
| 257 | - throw new \InvalidArgumentException("Blank is not an valid argument"); |
|
| 260 | + if( trim($arg) === "" ) { |
|
| 261 | + throw new \InvalidArgumentException("Blank is not an valid argument"); |
|
| 262 | + } |
|
| 258 | 263 | } |
| 259 | 264 | |
| 260 | 265 | private function eventMustExistOrFail($event) |
| 261 | 266 | { |
| 262 | - if( !( isset($this->sm[$this->currentState][$event]) ) ) |
|
| 263 | - throw new \InvalidArgumentException("Unexpected event '{$event}' on '{$this->currentState}' state"); |
|
| 267 | + if( !( isset($this->sm[$this->currentState][$event]) ) ) { |
|
| 268 | + throw new \InvalidArgumentException("Unexpected event '{$event}' on '{$this->currentState}' state"); |
|
| 269 | + } |
|
| 264 | 270 | } |
| 265 | 271 | |
| 266 | 272 | private function stateMustExistOrFail($state) |
| 267 | 273 | { |
| 268 | - if( ! isset($this->sm[$state]) ) |
|
| 269 | - throw new \InvalidArgumentException("Event '{$this->currentEvent}' fired to unadded '{$state}' state"); |
|
| 274 | + if( ! isset($this->sm[$state]) ) { |
|
| 275 | + throw new \InvalidArgumentException("Event '{$this->currentEvent}' fired to unadded '{$state}' state"); |
|
| 276 | + } |
|
| 270 | 277 | } |
| 271 | 278 | |
| 272 | 279 | private function setCurrentStateIfThisIsInitialState($state): void |