@@ -8,8 +8,8 @@ discard block |
||
| 8 | 8 | private const NEXT_STATE = 0; |
| 9 | 9 | private const EXEC_ACTION = 1; |
| 10 | 10 | |
| 11 | - protected $sm = array(); |
|
| 12 | - protected $currentState = null; |
|
| 11 | + protected $sm = array(); |
|
| 12 | + protected $currentState = null; |
|
| 13 | 13 | protected $currentEvent = null; |
| 14 | 14 | protected $nextState = null; |
| 15 | 15 | |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | private $eventsQueue = []; |
| 19 | 19 | private $commonTransition = []; |
| 20 | 20 | |
| 21 | - public function __construct(StateMachineBuilder $smb = null) |
|
| 21 | + public function __construct(StateMachineBuilder $smb = null) |
|
| 22 | 22 | { |
| 23 | 23 | if( $smb != null ) |
| 24 | 24 | $sm = $smb->__invoke(); |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | public function addState($state) |
| 42 | 42 | { |
| 43 | - $this->argumentIsValidOrFail($state); |
|
| 43 | + $this->argumentIsValidOrFail($state); |
|
| 44 | 44 | |
| 45 | 45 | $this->setCurrentStateIfThisIsInitialState($state); |
| 46 | 46 | |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | $this->argumentIsValidOrFail($currEvent); |
| 56 | 56 | $this->argumentIsValidOrFail($nextState); |
| 57 | 57 | |
| 58 | - $this->setCurrentStateIfThisIsInitialState($currState); |
|
| 58 | + $this->setCurrentStateIfThisIsInitialState($currState); |
|
| 59 | 59 | |
| 60 | 60 | $this->sm[$currState][$currEvent] = [ |
| 61 | 61 | self::NEXT_STATE => $nextState, |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | $this->commonTransition[$currentEvent] = [ |
| 73 | 73 | self::NEXT_STATE => $nextState, |
| 74 | 74 | self::EXEC_ACTION => $execAction |
| 75 | - ]; |
|
| 75 | + ]; |
|
| 76 | 76 | return $this; |
| 77 | 77 | } |
| 78 | 78 | |
@@ -178,11 +178,11 @@ discard block |
||
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | - public function dumpStates(){ |
|
| 182 | - var_dump(array_keys($this->sm)); |
|
| 183 | - } |
|
| 181 | + public function dumpStates(){ |
|
| 182 | + var_dump(array_keys($this->sm)); |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - public function dumpEvents(){ |
|
| 186 | - var_dump($this->sm); |
|
| 187 | - } |
|
| 185 | + public function dumpEvents(){ |
|
| 186 | + var_dump($this->sm); |
|
| 187 | + } |
|
| 188 | 188 | } |
@@ -20,8 +20,9 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | public function __construct(StateMachineBuilder $smb = null) |
| 22 | 22 | { |
| 23 | - if( $smb != null ) |
|
| 24 | - $sm = $smb->__invoke(); |
|
| 23 | + if( $smb != null ) { |
|
| 24 | + $sm = $smb->__invoke(); |
|
| 25 | + } |
|
| 25 | 26 | |
| 26 | 27 | if( ! empty($sm) ){ |
| 27 | 28 | // StateEnum::CURRENT_STATE => [ EventEnum::ON_EVENT => [ StateEnum::NEXT_STATE_2, ActionClosureOrFunction ] ], |
@@ -149,26 +150,30 @@ discard block |
||
| 149 | 150 | |
| 150 | 151 | private function argumentIsNotNullOrFail($arg): void |
| 151 | 152 | { |
| 152 | - if( $arg === null ) |
|
| 153 | - throw new \InvalidArgumentException("Null is not an valid argument"); |
|
| 153 | + if( $arg === null ) { |
|
| 154 | + throw new \InvalidArgumentException("Null is not an valid argument"); |
|
| 155 | + } |
|
| 154 | 156 | } |
| 155 | 157 | |
| 156 | 158 | private function argumentIsNotBlankOrFail($arg): void |
| 157 | 159 | { |
| 158 | - if( trim($arg) === "" ) |
|
| 159 | - throw new \InvalidArgumentException("Blank is not an valid argument"); |
|
| 160 | + if( trim($arg) === "" ) { |
|
| 161 | + throw new \InvalidArgumentException("Blank is not an valid argument"); |
|
| 162 | + } |
|
| 160 | 163 | } |
| 161 | 164 | |
| 162 | 165 | private function eventMustExistOrFail($event) |
| 163 | 166 | { |
| 164 | - if( !( isset($this->sm[$this->currentState][$event]) || isset($this->commonTransition[$event]) ) ) |
|
| 165 | - throw new \InvalidArgumentException("Unexpected event {$event} on {$this->currentState} state"); |
|
| 167 | + if( !( isset($this->sm[$this->currentState][$event]) || isset($this->commonTransition[$event]) ) ) { |
|
| 168 | + throw new \InvalidArgumentException("Unexpected event {$event} on {$this->currentState} state"); |
|
| 169 | + } |
|
| 166 | 170 | } |
| 167 | 171 | |
| 168 | 172 | private function stateMustExistOrFail($state) |
| 169 | 173 | { |
| 170 | - if( ! isset($this->sm[$this->currentState]) ) |
|
| 171 | - throw new \InvalidArgumentException("Event {$this->currentEvent} fired an unexpected {$this->currentState} state"); |
|
| 174 | + if( ! isset($this->sm[$this->currentState]) ) { |
|
| 175 | + throw new \InvalidArgumentException("Event {$this->currentEvent} fired an unexpected {$this->currentState} state"); |
|
| 176 | + } |
|
| 172 | 177 | } |
| 173 | 178 | |
| 174 | 179 | private function setCurrentStateIfThisIsInitialState($state): void |