Completed
Push — master ( 23291c...c26772 )
by Jean
01:56
created
src/DeferredCallChain.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
      * 
34 34
      * @param string $key The entry to acces
35 35
      */
36
-    public function __construct($class_type_or_instance=null)
36
+    public function __construct($class_type_or_instance = null)
37 37
     {
38 38
         if ($class_type_or_instance) {
39 39
             $this->expectedTarget = $class_type_or_instance;
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
         foreach ($this->stack as $i => $call) {
103 103
             if (isset($call['method'])) {
104 104
                 $string .= '->';
105
-                $string .= $call['method'].'(';
105
+                $string .= $call['method'] . '(';
106 106
                 $string .= implode(', ', array_map(function($argument) {
107 107
                     return var_export($argument, true);
108 108
                 }, $call['arguments']));
@@ -134,12 +134,12 @@  discard block
 block discarded – undo
134 134
         }
135 135
         elseif (is_string($this->expectedTarget)) {
136 136
             if (class_exists($this->expectedTarget)) {
137
-                if (! $target instanceof $this->expectedTarget) {
137
+                if (!$target instanceof $this->expectedTarget) {
138 138
                     throw new BadTargetClassException($this, $this->expectedTarget, $target);
139 139
                 }
140 140
             }
141 141
             elseif (interface_exists($this->expectedTarget)) {
142
-                if (! $target instanceof $this->expectedTarget) {
142
+                if (!$target instanceof $this->expectedTarget) {
143 143
                     throw new BadTargetInterfaceException($this, $this->expectedTarget, $target);
144 144
                 }
145 145
             }
@@ -186,14 +186,14 @@  discard block
 block discarded – undo
186 186
         catch (\BadMethodCallException $e) {
187 187
             if (
188 188
                 (
189
-                    (  PHP_VERSION_ID < 70000
189
+                    (PHP_VERSION_ID < 70000
190 190
                         && $e->getTrace()[2]['file'] == __FILE__
191 191
                         && $e->getTrace()[2]['function'] == 'call_user_func_array'
192 192
                         && $e->getTrace()[1]['function'] == $method_name
193 193
                         && $e->getTrace()[1]['class'] == get_class($current_chained_subject)
194 194
                     )
195 195
                     ||
196
-                    (   PHP_VERSION_ID >= 70000
196
+                    (PHP_VERSION_ID >= 70000
197 197
                         && $e->getTrace()[1]['file'] == __FILE__
198 198
                         && $e->getTrace()[1]['function'] == 'call_user_func_array'
199 199
                         // The magic method call doesn't exist in the stack with PHP 7
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
      * @param  $target The target to apply the callchain on
219 219
      * @return The value returned once the call chain is called uppon $target
220 220
      */
221
-    public function __invoke($target=null)
221
+    public function __invoke($target = null)
222 222
     {
223 223
         $out = $this->checkTarget($target);
224 224
         
@@ -234,13 +234,13 @@  discard block
 block discarded – undo
234 234
                         );
235 235
                     }
236 236
                     
237
-                    if (! $is_called && is_callable($call['method'])) {
237
+                    if (!$is_called && is_callable($call['method'])) {
238 238
                         $arguments = $this->prepareArgs($call['arguments'], $out);
239 239
                         $out = call_user_func_array($call['method'], $arguments);
240 240
                         $is_called = true;
241 241
                     }
242 242
                     
243
-                    if (! $is_called) {
243
+                    if (!$is_called) {
244 244
                         throw new \BadMethodCallException(
245 245
                             $call['method'] . "() is neither a method of " . get_class($out)
246 246
                             . " nor a function"
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
                     }
249 249
                 }
250 250
                 else {
251
-                    $out = $out[ $call['entry'] ];
251
+                    $out = $out[$call['entry']];
252 252
                 }
253 253
             }
254 254
             catch (\Exception $e) {
Please login to merge, or discard this patch.
Braces   +11 added lines, -22 removed lines patch added patch discarded remove patch
@@ -93,8 +93,7 @@  discard block
 block discarded – undo
93 93
         $string = '(new ' . get_called_class();
94 94
         if (is_string($this->expectedTarget)) {
95 95
             $string .= '(' . var_export($this->expectedTarget, true) . ')';
96
-        }
97
-        elseif (is_object($this->expectedTarget)) {
96
+        } elseif (is_object($this->expectedTarget)) {
98 97
             $string .= '( ' . get_class($this->expectedTarget) . '#' . spl_object_id($this->expectedTarget) . ' )';
99 98
         }
100 99
         $string .= ')';
@@ -107,8 +106,7 @@  discard block
 block discarded – undo
107 106
                     return var_export($argument, true);
108 107
                 }, $call['arguments']));
109 108
                 $string .= ')';
110
-            }
111
-            else {
109
+            } else {
112 110
                 $string .= '[' . var_export($call['entry'], true) . ']';
113 111
             }
114 112
         }
@@ -131,30 +129,25 @@  discard block
 block discarded – undo
131 129
             }
132 130
             
133 131
             $out = $this->expectedTarget;
134
-        }
135
-        elseif (is_string($this->expectedTarget)) {
132
+        } elseif (is_string($this->expectedTarget)) {
136 133
             if (class_exists($this->expectedTarget)) {
137 134
                 if (! $target instanceof $this->expectedTarget) {
138 135
                     throw new BadTargetClassException($this, $this->expectedTarget, $target);
139 136
                 }
140
-            }
141
-            elseif (interface_exists($this->expectedTarget)) {
137
+            } elseif (interface_exists($this->expectedTarget)) {
142 138
                 if (! $target instanceof $this->expectedTarget) {
143 139
                     throw new BadTargetInterfaceException($this, $this->expectedTarget, $target);
144 140
                 }
145
-            }
146
-            elseif (type_exists($this->expectedTarget)) {
141
+            } elseif (type_exists($this->expectedTarget)) {
147 142
                 if (gettype($target) != $this->expectedTarget) {
148 143
                     throw new BadTargetTypeException($this, $this->expectedTarget, $target);
149 144
                 }
150
-            }
151
-            else {
145
+            } else {
152 146
                 throw new UndefinedTargetClassException($this, $this->expectedTarget);
153 147
             }
154 148
             
155 149
             $out = $target;
156
-        }
157
-        else {
150
+        } else {
158 151
             $out = $target;
159 152
         }
160 153
         
@@ -182,8 +175,7 @@  discard block
 block discarded – undo
182 175
                 [$current_chained_subject, $method_name], 
183 176
                 $arguments
184 177
             );
185
-        }
186
-        catch (\BadMethodCallException $e) {
178
+        } catch (\BadMethodCallException $e) {
187 179
             if (
188 180
                 (
189 181
                     (  PHP_VERSION_ID < 70000
@@ -203,8 +195,7 @@  discard block
 block discarded – undo
203 195
                 && $e->getTrace()[0]['class'] == get_class($current_chained_subject)
204 196
             ) {
205 197
                 $is_called = false;
206
-            }
207
-            else {
198
+            } else {
208 199
                 throw $e;
209 200
             }
210 201
         }
@@ -246,12 +237,10 @@  discard block
 block discarded – undo
246 237
                             . " nor a function"
247 238
                         );
248 239
                     }
249
-                }
250
-                else {
240
+                } else {
251 241
                     $out = $out[ $call['entry'] ];
252 242
                 }
253
-            }
254
-            catch (\Exception $e) {
243
+            } catch (\Exception $e) {
255 244
                 // Throw $e with the good stack (usage exception)
256 245
                 throw $e;
257 246
             }
Please login to merge, or discard this patch.