@@ -14,7 +14,7 @@ |
||
| 14 | 14 | { |
| 15 | 15 | public function __construct($callchain, $expected_target, $target) |
| 16 | 16 | { |
| 17 | - $this->message = "You are trying to define a target of type ".gettype($target)." for the $callchain allowing only: ".$expected_target; |
|
| 17 | + $this->message = "You are trying to define a target of type " . gettype($target) . " for the $callchain allowing only: " . $expected_target; |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | /**/ |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | { |
| 15 | 15 | public function __construct($callchain, $expected_target, $target) |
| 16 | 16 | { |
| 17 | - $this->message = "You are trying to define a target of class ".get_class($target)." for the $callchain allowing only targets of class ".$expected_target; |
|
| 17 | + $this->message = "You are trying to define a target of class " . get_class($target) . " for the $callchain allowing only targets of class " . $expected_target; |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | /**/ |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | { |
| 15 | 15 | public function __construct($callchain, $expected_target) |
| 16 | 16 | { |
| 17 | - $this->message = "The expected target of $callchain is neither a defined class nor a native type: ". $expected_target; |
|
| 17 | + $this->message = "The expected target of $callchain is neither a defined class nor a native type: " . $expected_target; |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | /**/ |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | { |
| 15 | 15 | public function __construct($callchain, $expected_target, $target) |
| 16 | 16 | { |
| 17 | - $this->message = "You are trying to define a target of class ".get_class($target)." for the $callchain allowing only targets implementing ".$expected_target; |
|
| 17 | + $this->message = "You are trying to define a target of class " . get_class($target) . " for the $callchain allowing only targets implementing " . $expected_target; |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | /**/ |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | { |
| 15 | 15 | public function __construct($callchain, $expected_target, $target) |
| 16 | 16 | { |
| 17 | - $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); |
|
| 17 | + $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); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | /**/ |
@@ -93,8 +93,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 | |
@@ -179,8 +172,7 @@ discard block |
||
| 179 | 172 | $is_called = true; |
| 180 | 173 | try { |
| 181 | 174 | $out = call_user_func_array([$out, $call['method']], $call['arguments']); |
| 182 | - } |
|
| 183 | - catch (\BadMethodCallException $e) { |
|
| 175 | + } catch (\BadMethodCallException $e) { |
|
| 184 | 176 | // Calling a method coded inside a magic __call |
| 185 | 177 | // can produce a BadMethodCallException and thus |
| 186 | 178 | // not be a callable |
@@ -193,8 +185,7 @@ discard block |
||
| 193 | 185 | && $e->getTrace()[0]['class'] == get_class($out) |
| 194 | 186 | ) { |
| 195 | 187 | $is_called = false; |
| 196 | - } |
|
| 197 | - else { |
|
| 188 | + } else { |
|
| 198 | 189 | throw $e; |
| 199 | 190 | } |
| 200 | 191 | } |
@@ -213,12 +204,10 @@ discard block |
||
| 213 | 204 | . " nor a function" |
| 214 | 205 | ); |
| 215 | 206 | } |
| 216 | - } |
|
| 217 | - else { |
|
| 207 | + } else { |
|
| 218 | 208 | $out = $out[ $call['entry'] ]; |
| 219 | 209 | } |
| 220 | - } |
|
| 221 | - catch (\Exception $e) { |
|
| 210 | + } catch (\Exception $e) { |
|
| 222 | 211 | // Throw $e with the good stack (usage exception) |
| 223 | 212 | throw $e; |
| 224 | 213 | } |
@@ -33,7 +33,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 | } |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | * @param $target The target to apply the callchain on |
| 168 | 168 | * @return The value returned once the call chain is called uppon $target |
| 169 | 169 | */ |
| 170 | - public function __invoke($target=null) |
|
| 170 | + public function __invoke($target = null) |
|
| 171 | 171 | { |
| 172 | 172 | $out = $this->checkTarget($target); |
| 173 | 173 | |
@@ -186,14 +186,14 @@ discard block |
||
| 186 | 186 | // not be a callable |
| 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'] == $call['method'] |
| 193 | 193 | && $e->getTrace()[1]['class'] == get_class($out) |
| 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 |
@@ -210,14 +210,14 @@ discard block |
||
| 210 | 210 | } |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - if (! $is_called && is_callable($call['method'])) { |
|
| 213 | + if (!$is_called && is_callable($call['method'])) { |
|
| 214 | 214 | $arguments = $this->prepareArgs($call['arguments'], $out); |
| 215 | 215 | |
| 216 | 216 | $out = call_user_func_array($call['method'], $arguments); |
| 217 | 217 | $is_called = true; |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - if (! $is_called) { |
|
| 220 | + if (!$is_called) { |
|
| 221 | 221 | throw new \BadMethodCallException( |
| 222 | 222 | $call['method'] . "() is neither a method of " . get_class($out) |
| 223 | 223 | . " nor a function" |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | } |
| 226 | 226 | } |
| 227 | 227 | else { |
| 228 | - $out = $out[ $call['entry'] ]; |
|
| 228 | + $out = $out[$call['entry']]; |
|
| 229 | 229 | } |
| 230 | 230 | } |
| 231 | 231 | catch (\Exception $e) { |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | * @param mixed $value |
| 23 | 23 | * @return array |
| 24 | 24 | */ |
| 25 | - protected function prepareArgs (array $args, $value) |
|
| 25 | + protected function prepareArgs(array $args, $value) |
|
| 26 | 26 | { |
| 27 | 27 | return $this->hasPlaceholder($args) |
| 28 | 28 | ? $this->replacePlaceholderWithValue($args, $value) |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @param array $args |
| 35 | 35 | * @return bool |
| 36 | 36 | */ |
| 37 | - protected function hasPlaceholder (array $args) |
|
| 37 | + protected function hasPlaceholder(array $args) |
|
| 38 | 38 | { |
| 39 | 39 | return in_array($this->placeholder, $args, true); |
| 40 | 40 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * @param array $args |
| 45 | 45 | * @return array |
| 46 | 46 | */ |
| 47 | - protected function addValueAsFirstArg (array $args, $value) |
|
| 47 | + protected function addValueAsFirstArg(array $args, $value) |
|
| 48 | 48 | { |
| 49 | 49 | array_unshift($args, $value); |
| 50 | 50 | |
@@ -57,9 +57,9 @@ discard block |
||
| 57 | 57 | * @param mixed $value |
| 58 | 58 | * @return array |
| 59 | 59 | */ |
| 60 | - protected function replacePlaceholderWithValue (array $args, $value) |
|
| 60 | + protected function replacePlaceholderWithValue(array $args, $value) |
|
| 61 | 61 | { |
| 62 | - return array_map(function ($arg) use ($value) { |
|
| 62 | + return array_map(function($arg) use ($value) { |
|
| 63 | 63 | return $arg === $this->placeholder |
| 64 | 64 | ? $value |
| 65 | 65 | : $arg; |