@@ -45,21 +45,21 @@ discard block |
||
| 45 | 45 | $target = isset($options['target']) ? $options['target'] : $this->expectedTarget; |
| 46 | 46 | $max_param_length = isset($options['max_parameter_length']) ? $options['max_parameter_length'] : 56; |
| 47 | 47 | $short_objects = isset($options['short_objects']) ? $options['short_objects'] : true; |
| 48 | - $string = '(new ' . get_called_class(); |
|
| 49 | - $target && ($string .= '(' . static::varExport($target, ['short_objects' => $short_objects, 'max_length' => $max_param_length]) . ')'); |
|
| 48 | + $string = '(new '.get_called_class(); |
|
| 49 | + $target && ($string .= '('.static::varExport($target, ['short_objects' => $short_objects, 'max_length' => $max_param_length]).')'); |
|
| 50 | 50 | $string .= ')'; |
| 51 | 51 | foreach ($this->stack as $i => $call) { |
| 52 | 52 | if (isset($call['method'])) { |
| 53 | 53 | $string .= '->'; |
| 54 | - $string .= $call['method'] . '('; |
|
| 55 | - $string .= implode(', ', array_map(function ($argument) use($max_param_length, $short_objects) { |
|
| 54 | + $string .= $call['method'].'('; |
|
| 55 | + $string .= implode(', ', array_map(function($argument) use($max_param_length, $short_objects) { |
|
| 56 | 56 | return static::varExport($argument, ['short_objects' => $short_objects, 'max_length' => $max_param_length]); |
| 57 | 57 | }, $call['arguments'])); |
| 58 | 58 | $string .= ')'; |
| 59 | 59 | } else { |
| 60 | - $string .= '[' . static::varExport($call['entry'], ['short_objects' => $short_objects, 'max_length' => $max_param_length]) . ']'; |
|
| 60 | + $string .= '['.static::varExport($call['entry'], ['short_objects' => $short_objects, 'max_length' => $max_param_length]).']'; |
|
| 61 | 61 | } |
| 62 | - if (!empty($options['limit']) && $options['limit'] == $i) { |
|
| 62 | + if ( ! empty($options['limit']) && $options['limit'] == $i) { |
|
| 63 | 63 | break; |
| 64 | 64 | } |
| 65 | 65 | } |
@@ -75,20 +75,20 @@ discard block |
||
| 75 | 75 | protected static function varExport($variable, array $options = []) |
| 76 | 76 | { |
| 77 | 77 | $options['max_length'] = isset($options['max_length']) ? $options['max_length'] : 56; |
| 78 | - $options['short_objects'] = !empty($options['short_objects']) || in_array('short_objects', $options); |
|
| 78 | + $options['short_objects'] = ! empty($options['short_objects']) || in_array('short_objects', $options); |
|
| 79 | 79 | $export = var_export($variable, true); |
| 80 | 80 | if ($options['short_objects']) { |
| 81 | 81 | if (is_object($variable)) { |
| 82 | - $export = ' ' . get_class($variable) . ' #' . spl_object_id($variable) . ' '; |
|
| 82 | + $export = ' '.get_class($variable).' #'.spl_object_id($variable).' '; |
|
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | if (strlen($export) > $options['max_length']) { |
| 86 | 86 | if (is_object($variable)) { |
| 87 | 87 | // shortening short objects would only slow the workflow |
| 88 | - $export = get_class($variable) . ' #' . spl_object_id($variable); |
|
| 88 | + $export = get_class($variable).' #'.spl_object_id($variable); |
|
| 89 | 89 | } elseif (is_string($variable)) { |
| 90 | 90 | $keep_length = floor(($options['max_length'] - 5) / 2); |
| 91 | - $export = substr($variable, 0, (int) $keep_length) . ' ... ' . substr($variable, -$keep_length); |
|
| 91 | + $export = substr($variable, 0, (int) $keep_length).' ... '.substr($variable, -$keep_length); |
|
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | return $export; |
@@ -56,7 +56,8 @@ discard block |
||
| 56 | 56 | return static::varExport($argument, ['short_objects' => $short_objects, 'max_length' => $max_param_length]); |
| 57 | 57 | }, $call['arguments'])); |
| 58 | 58 | $string .= ')'; |
| 59 | - } else { |
|
| 59 | + } |
|
| 60 | + else { |
|
| 60 | 61 | $string .= '[' . static::varExport($call['entry'], ['short_objects' => $short_objects, 'max_length' => $max_param_length]) . ']'; |
| 61 | 62 | } |
| 62 | 63 | if (!empty($options['limit']) && $options['limit'] == $i) { |
@@ -86,7 +87,8 @@ discard block |
||
| 86 | 87 | if (is_object($variable)) { |
| 87 | 88 | // shortening short objects would only slow the workflow |
| 88 | 89 | $export = get_class($variable) . ' #' . spl_object_id($variable); |
| 89 | - } elseif (is_string($variable)) { |
|
| 90 | + } |
|
| 91 | + elseif (is_string($variable)) { |
|
| 90 | 92 | $keep_length = floor(($options['max_length'] - 5) / 2); |
| 91 | 93 | $export = substr($variable, 0, (int) $keep_length) . ' ... ' . substr($variable, -$keep_length); |
| 92 | 94 | } |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | /** |
| 4 | 4 | * File gathering functions |
| 5 | 5 | */ |
| 6 | -if (!function_exists('type_exists')) { |
|
| 6 | +if ( ! function_exists('type_exists')) { |
|
| 7 | 7 | /** |
| 8 | 8 | * Checks if a type is a valid PHP one. |
| 9 | 9 | * |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | return in_array($type_name, ["boolean", "integer", "double", "string", "array", "object", "resource", "resource (closed)", "NULL", "unknown type"]); |
| 16 | 16 | } |
| 17 | 17 | } |
| 18 | -if (!function_exists('later')) { |
|
| 18 | +if ( ! function_exists('later')) { |
|
| 19 | 19 | /** |
| 20 | 20 | * Create a deferred call chain in a functionnal way. |
| 21 | 21 | * |
@@ -1,7 +1,7 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -$version = explode('.',phpversion()); |
|
| 4 | -$version = $version[0] . '.' . $version[1]; |
|
| 3 | +$version = explode('.', phpversion()); |
|
| 4 | +$version = $version[0].'.'.$version[1]; |
|
| 5 | 5 | |
| 6 | 6 | if (PHP_VERSION_ID >= 70000) { |
| 7 | 7 | $root = 'src'; |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * |
| 37 | 37 | * @param string $class_type_interface_or_instance The expected target class/type/interface/instance |
| 38 | 38 | */ |
| 39 | - public function __construct($class_type_interface_or_instance=null) |
|
| 39 | + public function __construct($class_type_interface_or_instance = null) |
|
| 40 | 40 | { |
| 41 | 41 | if ($class_type_interface_or_instance) { |
| 42 | 42 | $this->expectedTarget = $class_type_interface_or_instance; |
@@ -101,12 +101,12 @@ discard block |
||
| 101 | 101 | } |
| 102 | 102 | elseif (is_string($this->expectedTarget)) { |
| 103 | 103 | if (class_exists($this->expectedTarget)) { |
| 104 | - if (! $target instanceof $this->expectedTarget) { |
|
| 104 | + if ( ! $target instanceof $this->expectedTarget) { |
|
| 105 | 105 | throw new BadTargetClassException($this, $this->expectedTarget, $target); |
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | 108 | elseif (interface_exists($this->expectedTarget)) { |
| 109 | - if (! $target instanceof $this->expectedTarget) { |
|
| 109 | + if ( ! $target instanceof $this->expectedTarget) { |
|
| 110 | 110 | throw new BadTargetInterfaceException($this, $this->expectedTarget, $target); |
| 111 | 111 | } |
| 112 | 112 | } |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | $class = $current_chained_subject; |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - $callable = $class .'::'. $method_name; |
|
| 161 | + $callable = $class.'::'.$method_name; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | $current_chained_subject = call_user_func_array( |
@@ -203,10 +203,10 @@ discard block |
||
| 203 | 203 | |
| 204 | 204 | return |
| 205 | 205 | ($trace[0]['function'] == '__call' || $trace[0]['function'] == '__callStatic') |
| 206 | - && $trace[0]['class'] == (is_string($current_chained_subject) |
|
| 206 | + && $trace[0]['class'] == (is_string($current_chained_subject) |
|
| 207 | 207 | ? $current_chained_subject |
| 208 | 208 | : get_class($current_chained_subject)) |
| 209 | - && $trace[0]['args'][0] == $method_name |
|
| 209 | + && $trace[0]['args'][0] == $method_name |
|
| 210 | 210 | && ( |
| 211 | 211 | $trace[$call_user_func_array_position]['file'] == __FILE__ |
| 212 | 212 | && $trace[$call_user_func_array_position]['function'] == 'call_user_func_array' |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | * @param mixed $target The target to apply the callchain on |
| 221 | 221 | * @return mixed The value returned once the call chain is called uppon $target |
| 222 | 222 | */ |
| 223 | - public function __invoke($target=null) |
|
| 223 | + public function __invoke($target = null) |
|
| 224 | 224 | { |
| 225 | 225 | $out = $this->checkTarget($target); |
| 226 | 226 | |
@@ -237,9 +237,9 @@ discard block |
||
| 237 | 237 | ); |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - if (! $is_called && ( |
|
| 241 | - (is_string($out) && is_callable($out .'::'.$call['method'])) |
|
| 242 | - || (is_object($out) && is_callable(get_class($out) .'::'.$call['method'])) |
|
| 240 | + if ( ! $is_called && ( |
|
| 241 | + (is_string($out) && is_callable($out.'::'.$call['method'])) |
|
| 242 | + || (is_object($out) && is_callable(get_class($out).'::'.$call['method'])) |
|
| 243 | 243 | ) |
| 244 | 244 | ) { |
| 245 | 245 | $is_called = $this->checkMethodIsReallyCallable( |
@@ -250,22 +250,22 @@ discard block |
||
| 250 | 250 | ); |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | - if (! $is_called && is_callable($call['method'])) { |
|
| 253 | + if ( ! $is_called && is_callable($call['method'])) { |
|
| 254 | 254 | $arguments = $this->prepareArgs($call['arguments'], $out); |
| 255 | 255 | $out = call_user_func_array($call['method'], $arguments); |
| 256 | 256 | $is_called = true; |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - if (! $is_called) { |
|
| 259 | + if ( ! $is_called) { |
|
| 260 | 260 | throw new \BadMethodCallException( |
| 261 | - $call['method'] . "() is neither a method of " |
|
| 261 | + $call['method']."() is neither a method of " |
|
| 262 | 262 | . (is_string($out) ? $out : get_class($out)) |
| 263 | 263 | . " nor a function" |
| 264 | 264 | ); |
| 265 | 265 | } |
| 266 | 266 | } |
| 267 | 267 | else { |
| 268 | - $out = $out[ $call['entry'] ]; |
|
| 268 | + $out = $out[$call['entry']]; |
|
| 269 | 269 | } |
| 270 | 270 | } |
| 271 | 271 | catch (\Exception $e) { |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | 'message', |
| 281 | 281 | $e->getMessage() |
| 282 | 282 | . "\nWhen applying $callchain_description defined at " |
| 283 | - . $call['file'] . ':' . $call['line'] |
|
| 283 | + . $call['file'].':'.$call['line'] |
|
| 284 | 284 | ); |
| 285 | 285 | |
| 286 | 286 | // Throw $e with the good stack (usage exception) |
@@ -81,11 +81,11 @@ discard block |
||
| 81 | 81 | $out = $this->expectedTarget; |
| 82 | 82 | } elseif (is_string($this->expectedTarget)) { |
| 83 | 83 | if (class_exists($this->expectedTarget)) { |
| 84 | - if (!$target instanceof $this->expectedTarget) { |
|
| 84 | + if ( ! $target instanceof $this->expectedTarget) { |
|
| 85 | 85 | throw new BadTargetClassException($this, $this->expectedTarget, $target); |
| 86 | 86 | } |
| 87 | 87 | } elseif (interface_exists($this->expectedTarget)) { |
| 88 | - if (!$target instanceof $this->expectedTarget) { |
|
| 88 | + if ( ! $target instanceof $this->expectedTarget) { |
|
| 89 | 89 | throw new BadTargetInterfaceException($this, $this->expectedTarget, $target); |
| 90 | 90 | } |
| 91 | 91 | } elseif (type_exists($this->expectedTarget)) { |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | } elseif (is_string($current_chained_subject)) { |
| 125 | 125 | $class = $current_chained_subject; |
| 126 | 126 | } |
| 127 | - $callable = $class . '::' . $method_name; |
|
| 127 | + $callable = $class.'::'.$method_name; |
|
| 128 | 128 | } |
| 129 | 129 | $current_chained_subject = call_user_func_array($callable, $arguments); |
| 130 | 130 | } catch (\BadMethodCallException $e) { |
@@ -169,23 +169,23 @@ discard block |
||
| 169 | 169 | if (is_callable([$out, $call['method']])) { |
| 170 | 170 | $is_called = $this->checkMethodIsReallyCallable('->', $out, $call['method'], $call['arguments']); |
| 171 | 171 | } |
| 172 | - if (!$is_called && (is_string($out) && is_callable($out . '::' . $call['method']) || is_object($out) && is_callable(get_class($out) . '::' . $call['method']))) { |
|
| 172 | + if ( ! $is_called && (is_string($out) && is_callable($out.'::'.$call['method']) || is_object($out) && is_callable(get_class($out).'::'.$call['method']))) { |
|
| 173 | 173 | $is_called = $this->checkMethodIsReallyCallable('::', $out, $call['method'], $call['arguments']); |
| 174 | 174 | } |
| 175 | - if (!$is_called && is_callable($call['method'])) { |
|
| 175 | + if ( ! $is_called && is_callable($call['method'])) { |
|
| 176 | 176 | $arguments = $this->prepareArgs($call['arguments'], $out); |
| 177 | 177 | $out = call_user_func_array($call['method'], $arguments); |
| 178 | 178 | $is_called = true; |
| 179 | 179 | } |
| 180 | - if (!$is_called) { |
|
| 181 | - throw new \BadMethodCallException($call['method'] . "() is neither a method of " . (is_string($out) ? $out : get_class($out)) . " nor a function"); |
|
| 180 | + if ( ! $is_called) { |
|
| 181 | + throw new \BadMethodCallException($call['method']."() is neither a method of ".(is_string($out) ? $out : get_class($out))." nor a function"); |
|
| 182 | 182 | } |
| 183 | 183 | } else { |
| 184 | 184 | $out = $out[$call['entry']]; |
| 185 | 185 | } |
| 186 | 186 | } catch (\Exception $e) { |
| 187 | 187 | $callchain_description = $this->toString(['target' => $target, 'limit' => $i]); |
| 188 | - VisibilityViolator::setHiddenProperty($e, 'message', $e->getMessage() . "\nWhen applying {$callchain_description} defined at " . $call['file'] . ':' . $call['line']); |
|
| 188 | + VisibilityViolator::setHiddenProperty($e, 'message', $e->getMessage()."\nWhen applying {$callchain_description} defined at ".$call['file'].':'.$call['line']); |
|
| 189 | 189 | // Throw $e with the good stack (usage exception) |
| 190 | 190 | throw $e; |
| 191 | 191 | } |
@@ -79,24 +79,29 @@ discard block |
||
| 79 | 79 | throw new TargetAlreadyDefinedException($this, $this->expectedTarget, $target); |
| 80 | 80 | } |
| 81 | 81 | $out = $this->expectedTarget; |
| 82 | - } elseif (is_string($this->expectedTarget)) { |
|
| 82 | + } |
|
| 83 | + elseif (is_string($this->expectedTarget)) { |
|
| 83 | 84 | if (class_exists($this->expectedTarget)) { |
| 84 | 85 | if (!$target instanceof $this->expectedTarget) { |
| 85 | 86 | throw new BadTargetClassException($this, $this->expectedTarget, $target); |
| 86 | 87 | } |
| 87 | - } elseif (interface_exists($this->expectedTarget)) { |
|
| 88 | + } |
|
| 89 | + elseif (interface_exists($this->expectedTarget)) { |
|
| 88 | 90 | if (!$target instanceof $this->expectedTarget) { |
| 89 | 91 | throw new BadTargetInterfaceException($this, $this->expectedTarget, $target); |
| 90 | 92 | } |
| 91 | - } elseif (type_exists($this->expectedTarget)) { |
|
| 93 | + } |
|
| 94 | + elseif (type_exists($this->expectedTarget)) { |
|
| 92 | 95 | if (gettype($target) != $this->expectedTarget) { |
| 93 | 96 | throw new BadTargetTypeException($this, $this->expectedTarget, $target); |
| 94 | 97 | } |
| 95 | - } else { |
|
| 98 | + } |
|
| 99 | + else { |
|
| 96 | 100 | throw new UndefinedTargetClassException($this, $this->expectedTarget); |
| 97 | 101 | } |
| 98 | 102 | $out = $target; |
| 99 | - } else { |
|
| 103 | + } |
|
| 104 | + else { |
|
| 100 | 105 | $out = $target; |
| 101 | 106 | } |
| 102 | 107 | return $out; |
@@ -118,19 +123,23 @@ discard block |
||
| 118 | 123 | try { |
| 119 | 124 | if ($method_type == '->') { |
| 120 | 125 | $callable = [$current_chained_subject, $method_name]; |
| 121 | - } elseif ($method_type == '::') { |
|
| 126 | + } |
|
| 127 | + elseif ($method_type == '::') { |
|
| 122 | 128 | if (is_object($current_chained_subject)) { |
| 123 | 129 | $class = get_class($current_chained_subject); |
| 124 | - } elseif (is_string($current_chained_subject)) { |
|
| 130 | + } |
|
| 131 | + elseif (is_string($current_chained_subject)) { |
|
| 125 | 132 | $class = $current_chained_subject; |
| 126 | 133 | } |
| 127 | 134 | $callable = $class . '::' . $method_name; |
| 128 | 135 | } |
| 129 | 136 | $current_chained_subject = call_user_func_array($callable, $arguments); |
| 130 | - } catch (\BadMethodCallException $e) { |
|
| 137 | + } |
|
| 138 | + catch (\BadMethodCallException $e) { |
|
| 131 | 139 | if ($this->exceptionTrownFromMagicCall($e->getTrace(), $current_chained_subject, $method_name)) { |
| 132 | 140 | $is_called = false; |
| 133 | - } else { |
|
| 141 | + } |
|
| 142 | + else { |
|
| 134 | 143 | throw $e; |
| 135 | 144 | } |
| 136 | 145 | } |
@@ -180,10 +189,12 @@ discard block |
||
| 180 | 189 | if (!$is_called) { |
| 181 | 190 | throw new \BadMethodCallException($call['method'] . "() is neither a method of " . (is_string($out) ? $out : get_class($out)) . " nor a function"); |
| 182 | 191 | } |
| 183 | - } else { |
|
| 192 | + } |
|
| 193 | + else { |
|
| 184 | 194 | $out = $out[$call['entry']]; |
| 185 | 195 | } |
| 186 | - } catch (\Exception $e) { |
|
| 196 | + } |
|
| 197 | + catch (\Exception $e) { |
|
| 187 | 198 | $callchain_description = $this->toString(['target' => $target, 'limit' => $i]); |
| 188 | 199 | VisibilityViolator::setHiddenProperty($e, 'message', $e->getMessage() . "\nWhen applying {$callchain_description} defined at " . $call['file'] . ':' . $call['line']); |
| 189 | 200 | // Throw $e with the good stack (usage exception) |