@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * @param mixed $value |
| 26 | 26 | * @return array |
| 27 | 27 | */ |
| 28 | - protected function prepareArgs (array $args, $value) |
|
| 28 | + protected function prepareArgs(array $args, $value) |
|
| 29 | 29 | { |
| 30 | 30 | return $this->hasPlaceholder($args) |
| 31 | 31 | ? $this->replacePlaceholderWithValue($args, $value) |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * @param array $args |
| 38 | 38 | * @return bool |
| 39 | 39 | */ |
| 40 | - protected function hasPlaceholder (array $args) |
|
| 40 | + protected function hasPlaceholder(array $args) |
|
| 41 | 41 | { |
| 42 | 42 | return in_array($this->placeholder, $args, true); |
| 43 | 43 | } |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * @param mixed $value |
| 49 | 49 | * @return array |
| 50 | 50 | */ |
| 51 | - protected function addValueAsFirstArg (array $args, $value) |
|
| 51 | + protected function addValueAsFirstArg(array $args, $value) |
|
| 52 | 52 | { |
| 53 | 53 | array_unshift($args, $value); |
| 54 | 54 | |
@@ -61,9 +61,9 @@ discard block |
||
| 61 | 61 | * @param mixed $value |
| 62 | 62 | * @return array |
| 63 | 63 | */ |
| 64 | - protected function replacePlaceholderWithValue (array $args, $value) |
|
| 64 | + protected function replacePlaceholderWithValue(array $args, $value) |
|
| 65 | 65 | { |
| 66 | - return array_map(function ($arg) use ($value) { |
|
| 66 | + return array_map(function($arg) use ($value) { |
|
| 67 | 67 | return $arg === $this->placeholder |
| 68 | 68 | ? $value |
| 69 | 69 | : $arg; |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | public function __construct(DeferredCallChain $callchain, $expected_target, $target) |
| 26 | 26 | { |
| 27 | - $this->message = "You are trying to define a target of type ".gettype($target)." for the $callchain allowing only: ".$expected_target; |
|
| 27 | + $this->message = "You are trying to define a target of type " . gettype($target) . " for the $callchain allowing only: " . $expected_target; |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /**/ |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | public function __construct(DeferredCallChain $callchain, $expected_target, $target) |
| 26 | 26 | { |
| 27 | - $this->message = "You are trying to define the target ".spl_object_id($target)." for the $callchain which already has one: ".spl_object_id($expected_target); |
|
| 27 | + $this->message = "You are trying to define the target " . spl_object_id($target) . " for the $callchain which already has one: " . spl_object_id($expected_target); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /**/ |
@@ -23,7 +23,7 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | public function __construct(DeferredCallChain $callchain, $expected_target) |
| 25 | 25 | { |
| 26 | - $this->message = "The expected target of $callchain is neither a existing class or interface nor a native type: ". $expected_target; |
|
| 26 | + $this->message = "The expected target of $callchain is neither a existing class or interface nor a native type: " . $expected_target; |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /**/ |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | public function __construct(DeferredCallChain $callchain, $expected_target, $target) |
| 26 | 26 | { |
| 27 | - $this->message = "You are trying to define a target of class ".get_class($target)." for the $callchain allowing only targets implementing ".$expected_target; |
|
| 27 | + $this->message = "You are trying to define a target of class " . get_class($target) . " for the $callchain allowing only targets implementing " . $expected_target; |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /**/ |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | public function __construct(DeferredCallChain $callchain, $expected_target, $target) |
| 26 | 26 | { |
| 27 | - $this->message = "You are trying to define a target of class ".get_class($target)." for the $callchain allowing only targets of class ".$expected_target; |
|
| 27 | + $this->message = "You are trying to define a target of class " . get_class($target) . " for the $callchain allowing only targets of class " . $expected_target; |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /**/ |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | * File gathering functions |
| 4 | 4 | */ |
| 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 | * |
@@ -27,14 +27,14 @@ discard block |
||
| 27 | 27 | } |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | -if (! function_exists('later')) { |
|
| 30 | +if (!function_exists('later')) { |
|
| 31 | 31 | /** |
| 32 | 32 | * Create a deferred call chain in a functionnal way. |
| 33 | 33 | * |
| 34 | 34 | * @param string $class_type_interface_or_instance The expected target class/type/interface/instance |
| 35 | 35 | * @return \JClaveau\Async\DeferredCallChain |
| 36 | 36 | */ |
| 37 | - function later($class_type_interface_or_instance=null) |
|
| 37 | + function later($class_type_interface_or_instance = null) |
|
| 38 | 38 | { |
| 39 | 39 | return new \JClaveau\Async\DeferredCallChain(...func_get_args()); |
| 40 | 40 | } |
@@ -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; |
@@ -83,12 +83,12 @@ discard block |
||
| 83 | 83 | } |
| 84 | 84 | elseif (is_string($this->expectedTarget)) { |
| 85 | 85 | if (class_exists($this->expectedTarget)) { |
| 86 | - if (! $target instanceof $this->expectedTarget) { |
|
| 86 | + if (!$target instanceof $this->expectedTarget) { |
|
| 87 | 87 | throw new BadTargetClassException($this, $this->expectedTarget, $target); |
| 88 | 88 | } |
| 89 | 89 | } |
| 90 | 90 | elseif (interface_exists($this->expectedTarget)) { |
| 91 | - if (! $target instanceof $this->expectedTarget) { |
|
| 91 | + if (!$target instanceof $this->expectedTarget) { |
|
| 92 | 92 | throw new BadTargetInterfaceException($this, $this->expectedTarget, $target); |
| 93 | 93 | } |
| 94 | 94 | } |
@@ -169,8 +169,8 @@ discard block |
||
| 169 | 169 | |
| 170 | 170 | return |
| 171 | 171 | $trace[0]['function'] == '__call' |
| 172 | - && $trace[0]['class'] == get_class($current_chained_subject) |
|
| 173 | - && $trace[0]['args'][0] == $method_name |
|
| 172 | + && $trace[0]['class'] == get_class($current_chained_subject) |
|
| 173 | + && $trace[0]['args'][0] == $method_name |
|
| 174 | 174 | && ( |
| 175 | 175 | $trace[$call_user_func_array_position]['file'] == __FILE__ |
| 176 | 176 | && $trace[$call_user_func_array_position]['function'] == 'call_user_func_array' |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | * @param mixed $target The target to apply the callchain on |
| 185 | 185 | * @return mixed The value returned once the call chain is called uppon $target |
| 186 | 186 | */ |
| 187 | - public function __invoke($target=null) |
|
| 187 | + public function __invoke($target = null) |
|
| 188 | 188 | { |
| 189 | 189 | $out = $this->checkTarget($target); |
| 190 | 190 | |
@@ -200,13 +200,13 @@ discard block |
||
| 200 | 200 | ); |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - if (! $is_called && is_callable($call['method'])) { |
|
| 203 | + if (!$is_called && is_callable($call['method'])) { |
|
| 204 | 204 | $arguments = $this->prepareArgs($call['arguments'], $out); |
| 205 | 205 | $out = call_user_func_array($call['method'], $arguments); |
| 206 | 206 | $is_called = true; |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - if (! $is_called) { |
|
| 209 | + if (!$is_called) { |
|
| 210 | 210 | throw new \BadMethodCallException( |
| 211 | 211 | $call['method'] . "() is neither a method of " . get_class($out) |
| 212 | 212 | . " nor a function" |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | } |
| 215 | 215 | } |
| 216 | 216 | else { |
| 217 | - $out = $out[ $call['entry'] ]; |
|
| 217 | + $out = $out[$call['entry']]; |
|
| 218 | 218 | } |
| 219 | 219 | } |
| 220 | 220 | catch (\Exception $e) { |
@@ -80,30 +80,25 @@ discard block |
||
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | $out = $this->expectedTarget; |
| 83 | - } |
|
| 84 | - elseif (is_string($this->expectedTarget)) { |
|
| 83 | + } elseif (is_string($this->expectedTarget)) { |
|
| 85 | 84 | if (class_exists($this->expectedTarget)) { |
| 86 | 85 | if (! $target instanceof $this->expectedTarget) { |
| 87 | 86 | throw new BadTargetClassException($this, $this->expectedTarget, $target); |
| 88 | 87 | } |
| 89 | - } |
|
| 90 | - elseif (interface_exists($this->expectedTarget)) { |
|
| 88 | + } elseif (interface_exists($this->expectedTarget)) { |
|
| 91 | 89 | if (! $target instanceof $this->expectedTarget) { |
| 92 | 90 | throw new BadTargetInterfaceException($this, $this->expectedTarget, $target); |
| 93 | 91 | } |
| 94 | - } |
|
| 95 | - elseif (type_exists($this->expectedTarget)) { |
|
| 92 | + } elseif (type_exists($this->expectedTarget)) { |
|
| 96 | 93 | if (gettype($target) != $this->expectedTarget) { |
| 97 | 94 | throw new BadTargetTypeException($this, $this->expectedTarget, $target); |
| 98 | 95 | } |
| 99 | - } |
|
| 100 | - else { |
|
| 96 | + } else { |
|
| 101 | 97 | throw new UndefinedTargetClassException($this, $this->expectedTarget); |
| 102 | 98 | } |
| 103 | 99 | |
| 104 | 100 | $out = $target; |
| 105 | - } |
|
| 106 | - else { |
|
| 101 | + } else { |
|
| 107 | 102 | $out = $target; |
| 108 | 103 | } |
| 109 | 104 | |
@@ -131,16 +126,14 @@ discard block |
||
| 131 | 126 | [$current_chained_subject, $method_name], |
| 132 | 127 | $arguments |
| 133 | 128 | ); |
| 134 | - } |
|
| 135 | - catch (\BadMethodCallException $e) { |
|
| 129 | + } catch (\BadMethodCallException $e) { |
|
| 136 | 130 | if ($this->exceptionTrownFromMagicCall( |
| 137 | 131 | $e->getTrace(), |
| 138 | 132 | $current_chained_subject, |
| 139 | 133 | $method_name |
| 140 | 134 | )) { |
| 141 | 135 | $is_called = false; |
| 142 | - } |
|
| 143 | - else { |
|
| 136 | + } else { |
|
| 144 | 137 | throw $e; |
| 145 | 138 | } |
| 146 | 139 | } |
@@ -212,12 +205,10 @@ discard block |
||
| 212 | 205 | . " nor a function" |
| 213 | 206 | ); |
| 214 | 207 | } |
| 215 | - } |
|
| 216 | - else { |
|
| 208 | + } else { |
|
| 217 | 209 | $out = $out[ $call['entry'] ]; |
| 218 | 210 | } |
| 219 | - } |
|
| 220 | - catch (\Exception $e) { |
|
| 211 | + } catch (\Exception $e) { |
|
| 221 | 212 | |
| 222 | 213 | $callchain_description = $this->toString([ |
| 223 | 214 | 'target' => $target, |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * |
| 41 | 41 | * @return string The PHP code corresponding to this call chain |
| 42 | 42 | */ |
| 43 | - protected function toString(array $options=[]) |
|
| 43 | + protected function toString(array $options = []) |
|
| 44 | 44 | { |
| 45 | 45 | $target = isset($options['target']) ? $options['target'] : $this->expectedTarget; |
| 46 | 46 | |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | foreach ($this->stack as $i => $call) { |
| 52 | 52 | if (isset($call['method'])) { |
| 53 | 53 | $string .= '->'; |
| 54 | - $string .= $call['method'].'('; |
|
| 54 | + $string .= $call['method'] . '('; |
|
| 55 | 55 | $string .= implode(', ', array_map(function($argument) { |
| 56 | 56 | return static::varExport($argument, ['short_objects']); |
| 57 | 57 | }, $call['arguments'])); |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | $string .= '[' . static::varExport($call['entry'], ['short_objects']) . ']'; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - if (! empty($options['limit']) && $options['limit'] == $i) { |
|
| 64 | + if (!empty($options['limit']) && $options['limit'] == $i) { |
|
| 65 | 65 | break; |
| 66 | 66 | } |
| 67 | 67 | } |
@@ -76,10 +76,10 @@ discard block |
||
| 76 | 76 | * @param array $options max_length | alias_instances |
| 77 | 77 | * @return string The PHP code of the variable |
| 78 | 78 | */ |
| 79 | - protected static function varExport($variable, array $options=[]) |
|
| 79 | + protected static function varExport($variable, array $options = []) |
|
| 80 | 80 | { |
| 81 | 81 | $options['max_length'] = isset($options['max_length']) ? $options['max_length'] : 512; |
| 82 | - $options['short_objects'] = ! empty($options['short_objects']) || in_array('short_objects', $options); |
|
| 82 | + $options['short_objects'] = !empty($options['short_objects']) || in_array('short_objects', $options); |
|
| 83 | 83 | |
| 84 | 84 | $export = var_export($variable, true); |
| 85 | 85 | |
@@ -56,8 +56,7 @@ discard block |
||
| 56 | 56 | return static::varExport($argument, ['short_objects']); |
| 57 | 57 | }, $call['arguments'])); |
| 58 | 58 | $string .= ')'; |
| 59 | - } |
|
| 60 | - else { |
|
| 59 | + } else { |
|
| 61 | 60 | $string .= '[' . static::varExport($call['entry'], ['short_objects']) . ']'; |
| 62 | 61 | } |
| 63 | 62 | |
@@ -93,8 +92,7 @@ discard block |
||
| 93 | 92 | |
| 94 | 93 | if (is_object($variable)) { |
| 95 | 94 | $export = get_class($variable) . ' #' . spl_object_id($variable); |
| 96 | - } |
|
| 97 | - elseif (is_string($variable)) { |
|
| 95 | + } elseif (is_string($variable)) { |
|
| 98 | 96 | $keep_length = floor(($options['max_length'] - 5) / 2); |
| 99 | 97 | |
| 100 | 98 | $export = substr($variable, 0, (int) $keep_length) |