@@ -19,15 +19,15 @@ discard block |
||
19 | 19 | |
20 | 20 | public function __construct(StateMachineBuilder $smb = null) |
21 | 21 | { |
22 | - if( $smb != null ) |
|
22 | + if ($smb != null) |
|
23 | 23 | $sm = $smb->__invoke(); |
24 | 24 | |
25 | - if( ! empty($sm) ){ |
|
25 | + if ( ! empty($sm)) { |
|
26 | 26 | // StateEnum::CURRENT_STATE => [ EventEnum::ON_EVENT => [ StateEnum::NEXT_STATE_2, ActionClosureOrFunction ] ], |
27 | - foreach ($sm as $state => $transition){ |
|
27 | + foreach ($sm as $state => $transition) { |
|
28 | 28 | $this->addState($state); |
29 | 29 | foreach ($transition as $onEvent => $nextStateAndAction) { |
30 | - if( array_key_exists(self::EXEC_ACTION, $nextStateAndAction) ) { |
|
30 | + if (array_key_exists(self::EXEC_ACTION, $nextStateAndAction)) { |
|
31 | 31 | $this->addTransition($state, $onEvent, $nextStateAndAction[self::NEXT_STATE], $nextStateAndAction[self::EXEC_ACTION]); |
32 | 32 | } else { |
33 | 33 | $this->addTransition($state, $onEvent, $nextStateAndAction[self::NEXT_STATE]); |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | return $this; |
49 | 49 | } |
50 | 50 | |
51 | - public function addTransition($currentState, $currentEvent, $nextState, \Closure $execAction = null ) |
|
51 | + public function addTransition($currentState, $currentEvent, $nextState, \Closure $execAction = null) |
|
52 | 52 | { |
53 | 53 | $this->argumentIsValidOrFail($currentState); |
54 | 54 | $this->argumentIsValidOrFail($currentEvent); |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | return $this; |
64 | 64 | } |
65 | 65 | |
66 | - public function addCommonTransition($currentEvent, $nextState, \Closure $execAction = null ) |
|
66 | + public function addCommonTransition($currentEvent, $nextState, \Closure $execAction = null) |
|
67 | 67 | { |
68 | 68 | $this->argumentIsValidOrFail($currentEvent); |
69 | 69 | $this->argumentIsValidOrFail($nextState); |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | { |
84 | 84 | $this->argumentIsValidOrFail($event); |
85 | 85 | |
86 | - if( $this->transitionInProgress ){ |
|
86 | + if ($this->transitionInProgress) { |
|
87 | 87 | array_push($this->eventsQueued, $event); |
88 | 88 | return $this; |
89 | 89 | } |
@@ -100,11 +100,11 @@ discard block |
||
100 | 100 | $this->currentEvent = $event; |
101 | 101 | |
102 | 102 | $action = $transition[self::EXEC_ACTION]; |
103 | - if( $action ){ |
|
103 | + if ($action) { |
|
104 | 104 | ($action)($this); |
105 | 105 | } |
106 | 106 | |
107 | - if( $this->cancelTransition ){ |
|
107 | + if ($this->cancelTransition) { |
|
108 | 108 | $this->cancelTransition = false; |
109 | 109 | } else { |
110 | 110 | $this->currentState = $transition[self::NEXT_STATE]; |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | |
113 | 113 | $this->transitionInProgress = false; |
114 | 114 | $event = array_shift($this->eventsQueued); |
115 | - if( $event != null ){ |
|
115 | + if ($event != null) { |
|
116 | 116 | $this->fireEvent($event); |
117 | 117 | } |
118 | 118 | |
@@ -121,10 +121,10 @@ discard block |
||
121 | 121 | |
122 | 122 | public function can($event) |
123 | 123 | { |
124 | - try{ |
|
124 | + try { |
|
125 | 125 | $this->eventMustExistOrFail($event); |
126 | 126 | $can = true; |
127 | - } catch(\InvalidArgumentException $e){ |
|
127 | + } catch (\InvalidArgumentException $e) { |
|
128 | 128 | $can = false; |
129 | 129 | } |
130 | 130 | return $can; |
@@ -163,31 +163,31 @@ discard block |
||
163 | 163 | |
164 | 164 | private function argumentIsNotNullOrFail($arg): void |
165 | 165 | { |
166 | - if( $arg === null ) |
|
166 | + if ($arg === null) |
|
167 | 167 | throw new \InvalidArgumentException("Null is not an valid argument"); |
168 | 168 | } |
169 | 169 | |
170 | 170 | private function argumentIsNotBlankOrFail($arg): void |
171 | 171 | { |
172 | - if( trim($arg) === "" ) |
|
172 | + if (trim($arg) === "") |
|
173 | 173 | throw new \InvalidArgumentException("Blank is not an valid argument"); |
174 | 174 | } |
175 | 175 | |
176 | 176 | private function eventMustExistOrFail($event) |
177 | 177 | { |
178 | - if( !( isset($this->sm[$this->currentState][$event]) ) ) |
|
178 | + if ( ! (isset($this->sm[$this->currentState][$event]))) |
|
179 | 179 | throw new \InvalidArgumentException("Unexpected event {$event} on {$this->currentState} state"); |
180 | 180 | } |
181 | 181 | |
182 | 182 | private function stateMustExistOrFail($state) |
183 | 183 | { |
184 | - if( ! isset($this->sm[$state]) ) |
|
184 | + if ( ! isset($this->sm[$state])) |
|
185 | 185 | throw new \InvalidArgumentException("Event '{$this->currentEvent}' fired an unexpected '{$state}' state"); |
186 | 186 | } |
187 | 187 | |
188 | 188 | private function setCurrentStateIfThisIsInitialState($state): void |
189 | 189 | { |
190 | - if( $this->currentState == null){ |
|
190 | + if ($this->currentState == null) { |
|
191 | 191 | $this->currentState = $state; |
192 | 192 | } |
193 | 193 | } |