Passed
Push — master ( 7a5dd1...cfa4be )
by Javier
03:16
created
src/StateMachine.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -23,12 +23,12 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
     }
Please login to merge, or discard this patch.