Passed
Push — master ( 9d2fb0...79d8ff )
by Jean
02:00
created
src/DeferredCallChain.php 2 patches
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
      * 
35 35
      * @param string $class_type_interface_or_instance The expected target class/type/interface/instance
36 36
      */
37
-    public function __construct($class_type_interface_or_instance=null)
37
+    public function __construct($class_type_interface_or_instance = null)
38 38
     {
39 39
         if ($class_type_interface_or_instance) {
40 40
             $this->expectedTarget = $class_type_interface_or_instance;
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
      *
109 109
      * @return string The PHP code corresponding to this call chain
110 110
      */
111
-    protected function toString(array $options=[])
111
+    protected function toString(array $options = [])
112 112
     {
113 113
         $target = isset($options['target']) ? $options['target'] : $this->expectedTarget;
114 114
         
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
         foreach ($this->stack as $i => $call) {
120 120
             if (isset($call['method'])) {
121 121
                 $string .= '->';
122
-                $string .= $call['method'].'(';
122
+                $string .= $call['method'] . '(';
123 123
                 $string .= implode(', ', array_map(function($argument) {
124 124
                     return static::varExport($argument, ['short_objects']);
125 125
                 }, $call['arguments']));
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
                 $string .= '[' . static::varExport($call['entry'], ['short_objects']) . ']';
130 130
             }
131 131
             
132
-            if (! empty($options['limit']) && $options['limit'] == $i) {
132
+            if (!empty($options['limit']) && $options['limit'] == $i) {
133 133
                 break;
134 134
             }
135 135
         }
@@ -144,10 +144,10 @@  discard block
 block discarded – undo
144 144
      * @param  array  $options max_length | alias_instances
145 145
      * @return string The PHP code of the variable
146 146
      */
147
-    protected static function varExport($variable, array $options=[])
147
+    protected static function varExport($variable, array $options = [])
148 148
     {
149 149
         $options['max_length']    = isset($options['max_length']) ? $options['max_length'] : 512;
150
-        $options['short_objects'] = ! empty($options['short_objects']) || in_array('short_objects', $options);
150
+        $options['short_objects'] = !empty($options['short_objects']) || in_array('short_objects', $options);
151 151
         
152 152
         $export = var_export($variable, true);
153 153
         
@@ -193,12 +193,12 @@  discard block
 block discarded – undo
193 193
         }
194 194
         elseif (is_string($this->expectedTarget)) {
195 195
             if (class_exists($this->expectedTarget)) {
196
-                if (! $target instanceof $this->expectedTarget) {
196
+                if (!$target instanceof $this->expectedTarget) {
197 197
                     throw new BadTargetClassException($this, $this->expectedTarget, $target);
198 198
                 }
199 199
             }
200 200
             elseif (interface_exists($this->expectedTarget)) {
201
-                if (! $target instanceof $this->expectedTarget) {
201
+                if (!$target instanceof $this->expectedTarget) {
202 202
                     throw new BadTargetInterfaceException($this, $this->expectedTarget, $target);
203 203
                 }
204 204
             }
@@ -279,8 +279,8 @@  discard block
 block discarded – undo
279 279
         
280 280
         return  
281 281
                 $trace[0]['function'] == '__call'
282
-            &&  $trace[0]['class']    == get_class($current_chained_subject)
283
-            &&  $trace[0]['args'][0]  == $method_name
282
+            &&  $trace[0]['class'] == get_class($current_chained_subject)
283
+            &&  $trace[0]['args'][0] == $method_name
284 284
             && (
285 285
                     $trace[$call_user_func_array_position]['file'] == __FILE__
286 286
                 &&  $trace[$call_user_func_array_position]['function'] == 'call_user_func_array'
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
      * @param  mixed $target The target to apply the callchain on
295 295
      * @return mixed The value returned once the call chain is called uppon $target
296 296
      */
297
-    public function __invoke($target=null)
297
+    public function __invoke($target = null)
298 298
     {
299 299
         $out = $this->checkTarget($target);
300 300
         
@@ -310,13 +310,13 @@  discard block
 block discarded – undo
310 310
                         );
311 311
                     }
312 312
                     
313
-                    if (! $is_called && is_callable($call['method'])) {
313
+                    if (!$is_called && is_callable($call['method'])) {
314 314
                         $arguments = $this->prepareArgs($call['arguments'], $out);
315 315
                         $out = call_user_func_array($call['method'], $arguments);
316 316
                         $is_called = true;
317 317
                     }
318 318
                     
319
-                    if (! $is_called) {
319
+                    if (!$is_called) {
320 320
                         throw new \BadMethodCallException(
321 321
                             $call['method'] . "() is neither a method of " . get_class($out)
322 322
                             . " nor a function"
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
                     }
325 325
                 }
326 326
                 else {
327
-                    $out = $out[ $call['entry'] ];
327
+                    $out = $out[$call['entry']];
328 328
                 }
329 329
             }
330 330
             catch (\Exception $e) {
Please login to merge, or discard this patch.
Braces   +11 added lines, -22 removed lines patch added patch discarded remove patch
@@ -124,8 +124,7 @@  discard block
 block discarded – undo
124 124
                     return static::varExport($argument, ['short_objects']);
125 125
                 }, $call['arguments']));
126 126
                 $string .= ')';
127
-            }
128
-            else {
127
+            } else {
129 128
                 $string .= '[' . static::varExport($call['entry'], ['short_objects']) . ']';
130 129
             }
131 130
             
@@ -161,8 +160,7 @@  discard block
 block discarded – undo
161 160
             
162 161
             if (is_object($variable)) {
163 162
                 $export = get_class($variable) . ' #' . spl_object_id($variable);
164
-            }
165
-            elseif (is_string($variable)) {
163
+            } elseif (is_string($variable)) {
166 164
                 $keep_length = ceil(($options['max_length'] - 5) / 2);
167 165
                 
168 166
                 $export = substr($variable, 0, $keep_length)
@@ -190,30 +188,25 @@  discard block
 block discarded – undo
190 188
             }
191 189
             
192 190
             $out = $this->expectedTarget;
193
-        }
194
-        elseif (is_string($this->expectedTarget)) {
191
+        } elseif (is_string($this->expectedTarget)) {
195 192
             if (class_exists($this->expectedTarget)) {
196 193
                 if (! $target instanceof $this->expectedTarget) {
197 194
                     throw new BadTargetClassException($this, $this->expectedTarget, $target);
198 195
                 }
199
-            }
200
-            elseif (interface_exists($this->expectedTarget)) {
196
+            } elseif (interface_exists($this->expectedTarget)) {
201 197
                 if (! $target instanceof $this->expectedTarget) {
202 198
                     throw new BadTargetInterfaceException($this, $this->expectedTarget, $target);
203 199
                 }
204
-            }
205
-            elseif (type_exists($this->expectedTarget)) {
200
+            } elseif (type_exists($this->expectedTarget)) {
206 201
                 if (gettype($target) != $this->expectedTarget) {
207 202
                     throw new BadTargetTypeException($this, $this->expectedTarget, $target);
208 203
                 }
209
-            }
210
-            else {
204
+            } else {
211 205
                 throw new UndefinedTargetClassException($this, $this->expectedTarget);
212 206
             }
213 207
             
214 208
             $out = $target;
215
-        }
216
-        else {
209
+        } else {
217 210
             $out = $target;
218 211
         }
219 212
         
@@ -241,16 +234,14 @@  discard block
 block discarded – undo
241 234
                 [$current_chained_subject, $method_name], 
242 235
                 $arguments
243 236
             );
244
-        }
245
-        catch (\BadMethodCallException $e) {
237
+        } catch (\BadMethodCallException $e) {
246 238
             if ($this->exceptionTrownFromMagicCall(
247 239
                 $e->getTrace(),
248 240
                 $current_chained_subject,
249 241
                 $method_name
250 242
             )) {
251 243
                 $is_called = false;
252
-            }
253
-            else {
244
+            } else {
254 245
                 throw $e;
255 246
             }
256 247
         }
@@ -322,12 +313,10 @@  discard block
 block discarded – undo
322 313
                             . " nor a function"
323 314
                         );
324 315
                     }
325
-                }
326
-                else {
316
+                } else {
327 317
                     $out = $out[ $call['entry'] ];
328 318
                 }
329
-            }
330
-            catch (\Exception $e) {
319
+            } catch (\Exception $e) {
331 320
                 
332 321
                 $callchain_description = $this->toString([
333 322
                     'target' => $target,
Please login to merge, or discard this patch.