Test Failed
Push — master ( bf7c2b...532ba1 )
by Javier
03:33
created
src/StateMachine.php 3 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -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
         if( $this->smb == null )
44 44
             return;
45 45
 
@@ -58,10 +58,10 @@  discard block
 block discarded – undo
58 58
     }
59 59
 
60 60
     public function addTransition($currentState, $currentEvent, $nextState,
61
-                                  /*\Closure|array*/ $execAction = null,
62
-                                  \Closure $execGuard = null,
63
-                                  \Closure $execBefore = null,
64
-                                  \Closure $execAfter = null)
61
+                                    /*\Closure|array*/ $execAction = null,
62
+                                    \Closure $execGuard = null,
63
+                                    \Closure $execBefore = null,
64
+                                    \Closure $execAfter = null)
65 65
     {
66 66
         $this->argumentIsValidOrFail($currentState);
67 67
         $this->argumentIsValidOrFail($currentEvent);
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 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,8 +39,8 @@  discard block
 block discarded – undo
39 39
         }
40 40
     }
41 41
 
42
-	public function to(){
43
-        if( $this->smb == null )
42
+	public function to() {
43
+        if ($this->smb == null)
44 44
             return;
45 45
 
46 46
         $this->smb->to($this->getMachineToArray());
@@ -69,8 +69,8 @@  discard block
 block discarded – undo
69 69
 
70 70
         $this->setCurrentStateIfThisIsInitialState($currentState);
71 71
 
72
-        if( is_array($execAction) ){
73
-            $this->sm[$currentState][$currentEvent] = [ self::NEXT_STATE => $nextState ];
72
+        if (is_array($execAction)) {
73
+            $this->sm[$currentState][$currentEvent] = [self::NEXT_STATE => $nextState];
74 74
             $arrayActions = $execAction;
75 75
             foreach ($arrayActions as $key => $value) {
76 76
                 $this->sm[$currentState][$currentEvent][$key] = $value;
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
         $this->currentEvent = $event;
131 131
 
132 132
         $wasGuarded = false;
133
-        if( array_key_exists(self::EXEC_GUARD, $transition) ){
133
+        if (array_key_exists(self::EXEC_GUARD, $transition)) {
134 134
             $guard = $transition[self::EXEC_GUARD];
135 135
             if ($guard) {
136 136
                 if (($guard)($this) === false)
@@ -138,19 +138,19 @@  discard block
 block discarded – undo
138 138
             }
139 139
         }
140 140
         if ( ! $wasGuarded) {
141
-            if( array_key_exists(self::EXEC_BEFORE, $transition) ) {
141
+            if (array_key_exists(self::EXEC_BEFORE, $transition)) {
142 142
                 $before = $transition[self::EXEC_BEFORE];
143 143
                 if ($before) {
144 144
                     ($before)($this);
145 145
                 }
146 146
             }
147
-            if( array_key_exists(self::EXEC_ACTION, $transition) ) {
147
+            if (array_key_exists(self::EXEC_ACTION, $transition)) {
148 148
                 $action = $transition[self::EXEC_ACTION];
149 149
                 if ($action) {
150 150
                     ($action)($this);
151 151
                 }
152 152
             }
153
-            if( array_key_exists(self::EXEC_AFTER, $transition) ) {
153
+            if (array_key_exists(self::EXEC_AFTER, $transition)) {
154 154
                 $after = $transition[self::EXEC_AFTER];
155 155
                 if ($after) {
156 156
                     ($after)($this);
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
             }
159 159
         }
160 160
 
161
-        if( $this->cancelTransition || $wasGuarded ){
161
+        if ($this->cancelTransition || $wasGuarded) {
162 162
             $this->cancelTransition = false;
163 163
         } else {
164 164
             $this->currentState = $transition[self::NEXT_STATE];
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 
167 167
         $this->transitionInProgress = false;
168 168
         $event = array_shift($this->eventsQueued);
169
-        if(  $event != null ){
169
+        if ($event != null) {
170 170
             $this->fireEvent($event);
171 171
         }
172 172
 
@@ -175,21 +175,21 @@  discard block
 block discarded – undo
175 175
 
176 176
     public function can($event)
177 177
     {
178
-        try{
178
+        try {
179 179
             $this->eventMustExistOrFail($event);
180
-        } catch(\InvalidArgumentException $e){
180
+        } catch (\InvalidArgumentException $e) {
181 181
             return false;
182 182
         }
183 183
 
184 184
         $transition = $this->sm[$this->currentState][$event];
185
-        if( ! array_key_exists(self::EXEC_GUARD, $transition)){
185
+        if ( ! array_key_exists(self::EXEC_GUARD, $transition)) {
186 186
             return true;
187 187
         }
188 188
 
189 189
         $can = true;
190 190
         $guard = $transition[self::EXEC_GUARD];
191
-        if( $guard ){
192
-            if( ($guard)($this) === false )
191
+        if ($guard) {
192
+            if (($guard)($this) === false)
193 193
                 $can = false;
194 194
         }
195 195
         return $can;
@@ -237,31 +237,31 @@  discard block
 block discarded – undo
237 237
 
238 238
     private function argumentIsNotNullOrFail($arg): void
239 239
     {
240
-        if( $arg === null )
240
+        if ($arg === null)
241 241
             throw new \InvalidArgumentException("Null is not an valid argument");
242 242
     }
243 243
 
244 244
     private function argumentIsNotBlankOrFail($arg): void
245 245
     {
246
-        if( trim($arg) === "" )
246
+        if (trim($arg) === "")
247 247
             throw new \InvalidArgumentException("Blank is not an valid argument");
248 248
     }
249 249
 
250 250
     private function eventMustExistOrFail($event)
251 251
     {
252
-        if( !( isset($this->sm[$this->currentState][$event]) ) )
252
+        if ( ! (isset($this->sm[$this->currentState][$event])))
253 253
             throw new \InvalidArgumentException("Unexpected event '{$event}' on '{$this->currentState}' state");
254 254
     }
255 255
 
256 256
     private function stateMustExistOrFail($state)
257 257
     {
258
-        if( ! isset($this->sm[$state]) )
258
+        if ( ! isset($this->sm[$state]))
259 259
             throw new \InvalidArgumentException("Event '{$this->currentEvent}' fired an unexpected '{$state}' state");
260 260
     }
261 261
 
262 262
     private function setCurrentStateIfThisIsInitialState($state): void
263 263
     {
264
-        if( $this->currentState == null){
264
+        if ($this->currentState == null) {
265 265
             $this->currentState = $state;
266 266
         }
267 267
     }
Please login to merge, or discard this patch.
Braces   +24 added lines, -16 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, ActionClosureOrFunction ] ],
@@ -40,8 +41,9 @@  discard block
 block discarded – undo
40 41
     }
41 42
 
42 43
 	public function to(){
43
-        if( $this->smb == null )
44
-            return;
44
+        if( $this->smb == null ) {
45
+                    return;
46
+        }
45 47
 
46 48
         $this->smb->to($this->getMachineToArray());
47 49
     }
@@ -133,8 +135,9 @@  discard block
 block discarded – undo
133 135
         if( array_key_exists(self::EXEC_GUARD, $transition) ){
134 136
             $guard = $transition[self::EXEC_GUARD];
135 137
             if ($guard) {
136
-                if (($guard)($this) === false)
137
-                    $wasGuarded = true;
138
+                if (($guard)($this) === false) {
139
+                                    $wasGuarded = true;
140
+                }
138 141
             }
139 142
         }
140 143
         if ( ! $wasGuarded) {
@@ -189,8 +192,9 @@  discard block
 block discarded – undo
189 192
         $can = true;
190 193
         $guard = $transition[self::EXEC_GUARD];
191 194
         if( $guard ){
192
-            if( ($guard)($this) === false )
193
-                $can = false;
195
+            if( ($guard)($this) === false ) {
196
+                            $can = false;
197
+            }
194 198
         }
195 199
         return $can;
196 200
     }
@@ -237,26 +241,30 @@  discard block
 block discarded – undo
237 241
 
238 242
     private function argumentIsNotNullOrFail($arg): void
239 243
     {
240
-        if( $arg === null )
241
-            throw new \InvalidArgumentException("Null is not an valid argument");
244
+        if( $arg === null ) {
245
+                    throw new \InvalidArgumentException("Null is not an valid argument");
246
+        }
242 247
     }
243 248
 
244 249
     private function argumentIsNotBlankOrFail($arg): void
245 250
     {
246
-        if( trim($arg) === "" )
247
-            throw new \InvalidArgumentException("Blank is not an valid argument");
251
+        if( trim($arg) === "" ) {
252
+                    throw new \InvalidArgumentException("Blank is not an valid argument");
253
+        }
248 254
     }
249 255
 
250 256
     private function eventMustExistOrFail($event)
251 257
     {
252
-        if( !( isset($this->sm[$this->currentState][$event]) ) )
253
-            throw new \InvalidArgumentException("Unexpected event '{$event}' on '{$this->currentState}' state");
258
+        if( !( isset($this->sm[$this->currentState][$event]) ) ) {
259
+                    throw new \InvalidArgumentException("Unexpected event '{$event}' on '{$this->currentState}' state");
260
+        }
254 261
     }
255 262
 
256 263
     private function stateMustExistOrFail($state)
257 264
     {
258
-        if( ! isset($this->sm[$state]) )
259
-            throw new \InvalidArgumentException("Event '{$this->currentEvent}' fired an unexpected '{$state}' state");
265
+        if( ! isset($this->sm[$state]) ) {
266
+                    throw new \InvalidArgumentException("Event '{$this->currentEvent}' fired an unexpected '{$state}' state");
267
+        }
260 268
     }
261 269
 
262 270
     private function setCurrentStateIfThisIsInitialState($state): void
Please login to merge, or discard this patch.