Passed
Push — master ( cf9b22...f8edaa )
by Javier
03:21
created
src/StateMachine.php 2 patches
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 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, ClosureOrFunctionsArray ] ],
31 31
             foreach ($this->smb as $state => $transition) {
32 32
                 $this->addState($state);
@@ -69,20 +69,20 @@  discard block
 block discarded – undo
69 69
 
70 70
         $this->setCurrentStateIfThisIsInitialState($currentState);
71 71
 
72
-        if( $execAction === null ){
73
-            $this->sm[$currentState][$currentEvent] = [ self::NEXT_STATE => $nextState ];
72
+        if ($execAction === null) {
73
+            $this->sm[$currentState][$currentEvent] = [self::NEXT_STATE => $nextState];
74 74
         } elseif (is_array($execAction)) {
75
-            $this->sm[$currentState][$currentEvent] = [ self::NEXT_STATE => $nextState ];
75
+            $this->sm[$currentState][$currentEvent] = [self::NEXT_STATE => $nextState];
76 76
             $arrayActions = $execAction;
77 77
             foreach ($arrayActions as $exec_action => $action) {
78
-                if( in_array($exec_action, [self::EXEC_ACTION, self::EXEC_GUARD, self::EXEC_BEFORE, self::EXEC_AFTER], true) ){
79
-                    if( $action === null )
78
+                if (in_array($exec_action, [self::EXEC_ACTION, self::EXEC_GUARD, self::EXEC_BEFORE, self::EXEC_AFTER], true)) {
79
+                    if ($action === null)
80 80
                         continue;
81 81
                     $this->argumentMustBeClosureOrFail($action);
82 82
                 }
83 83
                 $this->sm[$currentState][$currentEvent][$exec_action] = $action;
84 84
             }
85
-        } elseif($execAction instanceof \Closure) {
85
+        } elseif ($execAction instanceof \Closure) {
86 86
             $this->sm[$currentState][$currentEvent] = [
87 87
                                                         self::NEXT_STATE => $nextState,
88 88
                                                         self::EXEC_ACTION => $execAction
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 
133 133
         $wasGuarded = $this->execGuard($transition);
134 134
 
135
-        if (!$wasGuarded) {
135
+        if ( ! $wasGuarded) {
136 136
             $this->execAction(self::EXEC_BEFORE, $transition);
137 137
             $this->execAction(self::EXEC_ACTION, $transition);
138 138
             $this->execAction(self::EXEC_AFTER, $transition);
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
     private function execGuard($transition): bool
157 157
     {
158 158
         $wasGuarded = false;
159
-        if( array_key_exists(self::EXEC_GUARD, $transition) ){
159
+        if (array_key_exists(self::EXEC_GUARD, $transition)) {
160 160
             $guard = $transition[self::EXEC_GUARD];
161 161
             if ($guard) {
162 162
                 if (($guard)($this) === false)
@@ -180,9 +180,9 @@  discard block
 block discarded – undo
180 180
     {
181 181
         $this->argumentIsValidOrFail($event);
182 182
 
183
-        try{
183
+        try {
184 184
             $this->eventMustExistOrFail($event);
185
-        } catch(\InvalidArgumentException $e){
185
+        } catch (\InvalidArgumentException $e) {
186 186
             return false;
187 187
         }
188 188
 
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 
240 240
     private function setCurrentStateIfThisIsInitialState($state): void
241 241
     {
242
-        if( $this->currentState == null)
242
+        if ($this->currentState == null)
243 243
             $this->currentState = $state;
244 244
     }
245 245
 
@@ -251,31 +251,31 @@  discard block
 block discarded – undo
251 251
 
252 252
     private function argumentIsNotNullOrFail($arg): void
253 253
     {
254
-        if( $arg === null )
254
+        if ($arg === null)
255 255
             throw new \InvalidArgumentException("Null is not an valid argument");
256 256
     }
257 257
 
258 258
     private function argumentIsNotBlankOrFail($arg): void
259 259
     {
260
-        if( trim($arg) === "" )
260
+        if (trim($arg) === "")
261 261
             throw new \InvalidArgumentException("Blank is not an valid argument");
262 262
     }
263 263
 
264 264
     private function eventMustExistOrFail($event)
265 265
     {
266
-        if( !( isset($this->sm[$this->currentState][$event]) ) )
266
+        if ( ! (isset($this->sm[$this->currentState][$event])))
267 267
             throw new \InvalidArgumentException("Unexpected event '{$event}' on '{$this->currentState}' state");
268 268
     }
269 269
 
270 270
     private function stateMustExistOrFail($state)
271 271
     {
272
-        if( ! isset($this->sm[$state]) )
272
+        if ( ! isset($this->sm[$state]))
273 273
             throw new \InvalidArgumentException("Event '{$this->currentEvent}' fired to unadded '{$state}' state");
274 274
     }
275 275
 
276 276
     private function argumentMustBeClosureOrFail($action): void
277 277
     {
278
-        if( !($action instanceof \Closure) )
278
+        if ( ! ($action instanceof \Closure))
279 279
             throw new \InvalidArgumentException('execAction argument must be Closure or array');
280 280
     }
281 281
 }
Please login to merge, or discard this patch.
Braces   +27 added lines, -18 removed lines patch added patch discarded remove patch
@@ -23,8 +23,9 @@  discard block
 block discarded – undo
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, ClosureOrFunctionsArray ] ],
@@ -76,8 +77,9 @@  discard block
 block discarded – undo
76 77
             $arrayActions = $execAction;
77 78
             foreach ($arrayActions as $exec_action => $action) {
78 79
                 if( in_array($exec_action, [self::EXEC_ACTION, self::EXEC_GUARD, self::EXEC_BEFORE, self::EXEC_AFTER], true) ){
79
-                    if( $action === null )
80
-                        continue;
80
+                    if( $action === null ) {
81
+                                            continue;
82
+                    }
81 83
                     $this->argumentMustBeClosureOrFail($action);
82 84
                 }
83 85
                 $this->sm[$currentState][$currentEvent][$exec_action] = $action;
@@ -159,8 +161,9 @@  discard block
 block discarded – undo
159 161
         if( array_key_exists(self::EXEC_GUARD, $transition) ){
160 162
             $guard = $transition[self::EXEC_GUARD];
161 163
             if ($guard) {
162
-                if (($guard)($this) === false)
163
-                    $wasGuarded = true;
164
+                if (($guard)($this) === false) {
165
+                                    $wasGuarded = true;
166
+                }
164 167
             }
165 168
         }
166 169
         return $wasGuarded;
@@ -239,8 +242,9 @@  discard block
 block discarded – undo
239 242
 
240 243
     private function setCurrentStateIfThisIsInitialState($state): void
241 244
     {
242
-        if( $this->currentState == null)
243
-            $this->currentState = $state;
245
+        if( $this->currentState == null) {
246
+                    $this->currentState = $state;
247
+        }
244 248
     }
245 249
 
246 250
     private function argumentIsValidOrFail($arg): void
@@ -251,31 +255,36 @@  discard block
 block discarded – undo
251 255
 
252 256
     private function argumentIsNotNullOrFail($arg): void
253 257
     {
254
-        if( $arg === null )
255
-            throw new \InvalidArgumentException("Null is not an valid argument");
258
+        if( $arg === null ) {
259
+                    throw new \InvalidArgumentException("Null is not an valid argument");
260
+        }
256 261
     }
257 262
 
258 263
     private function argumentIsNotBlankOrFail($arg): void
259 264
     {
260
-        if( trim($arg) === "" )
261
-            throw new \InvalidArgumentException("Blank is not an valid argument");
265
+        if( trim($arg) === "" ) {
266
+                    throw new \InvalidArgumentException("Blank is not an valid argument");
267
+        }
262 268
     }
263 269
 
264 270
     private function eventMustExistOrFail($event)
265 271
     {
266
-        if( !( isset($this->sm[$this->currentState][$event]) ) )
267
-            throw new \InvalidArgumentException("Unexpected event '{$event}' on '{$this->currentState}' state");
272
+        if( !( isset($this->sm[$this->currentState][$event]) ) ) {
273
+                    throw new \InvalidArgumentException("Unexpected event '{$event}' on '{$this->currentState}' state");
274
+        }
268 275
     }
269 276
 
270 277
     private function stateMustExistOrFail($state)
271 278
     {
272
-        if( ! isset($this->sm[$state]) )
273
-            throw new \InvalidArgumentException("Event '{$this->currentEvent}' fired to unadded '{$state}' state");
279
+        if( ! isset($this->sm[$state]) ) {
280
+                    throw new \InvalidArgumentException("Event '{$this->currentEvent}' fired to unadded '{$state}' state");
281
+        }
274 282
     }
275 283
 
276 284
     private function argumentMustBeClosureOrFail($action): void
277 285
     {
278
-        if( !($action instanceof \Closure) )
279
-            throw new \InvalidArgumentException('execAction argument must be Closure or array');
286
+        if( !($action instanceof \Closure) ) {
287
+                    throw new \InvalidArgumentException('execAction argument must be Closure or array');
288
+        }
280 289
     }
281 290
 }
Please login to merge, or discard this patch.