@@ -49,17 +49,17 @@ discard block |
||
| 49 | 49 | */ |
| 50 | 50 | public function instantiate(\ReflectionClass $attr, array $arguments, \Reflector $context = null): object |
| 51 | 51 | { |
| 52 | - if ($this->isNamedArgumentsSupported()) { |
|
| 53 | - try { |
|
| 52 | + if ($this->isNamedArgumentsSupported()){ |
|
| 53 | + try{ |
|
| 54 | 54 | return $attr->newInstanceArgs($arguments); |
| 55 | - } catch (\Throwable $e) { |
|
| 55 | + }catch (\Throwable $e){ |
|
| 56 | 56 | throw Exception::withLocation($e, $attr->getFileName(), $attr->getStartLine()); |
| 57 | 57 | } |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | $constructor = $this->getConstructor($attr); |
| 61 | 61 | |
| 62 | - if ($constructor === null) { |
|
| 62 | + if ($constructor === null){ |
|
| 63 | 63 | return $attr->newInstanceWithoutConstructor(); |
| 64 | 64 | } |
| 65 | 65 | |
@@ -78,9 +78,9 @@ discard block |
||
| 78 | 78 | */ |
| 79 | 79 | private function resolveParameters(\ReflectionClass $ctx, \ReflectionMethod $constructor, array $arguments): array |
| 80 | 80 | { |
| 81 | - try { |
|
| 81 | + try{ |
|
| 82 | 82 | return $this->doResolveParameters($ctx, $constructor, $arguments); |
| 83 | - } catch (\Throwable $e) { |
|
| 83 | + }catch (\Throwable $e){ |
|
| 84 | 84 | throw Exception::withLocation($e, $constructor->getFileName(), $constructor->getStartLine()); |
| 85 | 85 | } |
| 86 | 86 | } |
@@ -92,16 +92,16 @@ discard block |
||
| 92 | 92 | { |
| 93 | 93 | $namedArgsBegin = $this->analyzeKeys($arguments); |
| 94 | 94 | |
| 95 | - if ($namedArgsBegin === null) { |
|
| 95 | + if ($namedArgsBegin === null){ |
|
| 96 | 96 | // Only numeric / positional keys exist. |
| 97 | 97 | return $arguments; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - if ($namedArgsBegin === 0) { |
|
| 100 | + if ($namedArgsBegin === 0){ |
|
| 101 | 101 | // Only named keys exist. |
| 102 | 102 | $passed = []; |
| 103 | 103 | $named = $arguments; |
| 104 | - } else { |
|
| 104 | + }else{ |
|
| 105 | 105 | // Numeric/positional keys followed by named keys. |
| 106 | 106 | // No need to preserve numeric keys. |
| 107 | 107 | $passed = array_slice($arguments, 0, $namedArgsBegin); |
@@ -135,11 +135,11 @@ discard block |
||
| 135 | 135 | $arguments = \array_merge($arguments); |
| 136 | 136 | |
| 137 | 137 | $i = 0; |
| 138 | - foreach ($arguments as $k => $_) { |
|
| 139 | - if ($k !== $i) { |
|
| 138 | + foreach ($arguments as $k => $_){ |
|
| 139 | + if ($k !== $i){ |
|
| 140 | 140 | // This must be a string key. |
| 141 | 141 | // Any further numeric keys are illegal. |
| 142 | - if (\array_key_exists($i, $arguments)) { |
|
| 142 | + if (\array_key_exists($i, $arguments)){ |
|
| 143 | 143 | throw new \BadMethodCallException(self::ERROR_POSITIONAL_AFTER_NAMED); |
| 144 | 144 | } |
| 145 | 145 | return $i; |
@@ -175,25 +175,25 @@ discard block |
||
| 175 | 175 | ): array { |
| 176 | 176 | // Analyze parameters. |
| 177 | 177 | $n = count($parameters); |
| 178 | - if ($n > 0 && end($parameters)->isVariadic()) { |
|
| 178 | + if ($n > 0 && end($parameters)->isVariadic()){ |
|
| 179 | 179 | $variadicParameter = end($parameters); |
| 180 | 180 | // Don't include the variadic parameter in the mapping process. |
| 181 | 181 | --$n; |
| 182 | - } else { |
|
| 182 | + }else{ |
|
| 183 | 183 | $variadicParameter = null; |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | // Process parameters that are not already filled with positional args. |
| 187 | 187 | // This loop will do nothing if $namedArgsBegin >= $n. That's ok. |
| 188 | - for ($i = $namedArgsBegin; $i < $n; ++$i) { |
|
| 188 | + for ($i = $namedArgsBegin; $i < $n; ++$i){ |
|
| 189 | 189 | $parameter = $parameters[$i]; |
| 190 | 190 | $k = $parameter->getName(); |
| 191 | - if (array_key_exists($k, $named)) { |
|
| 191 | + if (array_key_exists($k, $named)){ |
|
| 192 | 192 | $passed[] = $named[$k]; |
| 193 | 193 | unset($named[$k]); |
| 194 | - } elseif ($parameter->isDefaultValueAvailable()) { |
|
| 194 | + } elseif ($parameter->isDefaultValueAvailable()){ |
|
| 195 | 195 | $passed[] = $parameter->getDefaultValue(); |
| 196 | - } else { |
|
| 196 | + }else{ |
|
| 197 | 197 | $message = \vsprintf(self::ERROR_ARGUMENT_NOT_PASSED, [ |
| 198 | 198 | $ctx->getName(), |
| 199 | 199 | $parameter->getPosition() + 1, |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | } |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - if ($named === []) { |
|
| 207 | + if ($named === []){ |
|
| 208 | 208 | // No unknown argument names exist. |
| 209 | 209 | return $passed; |
| 210 | 210 | } |
@@ -214,11 +214,11 @@ discard block |
||
| 214 | 214 | $badArgName = key($named); |
| 215 | 215 | |
| 216 | 216 | // Check collision with positional arguments. |
| 217 | - foreach ($parameters as $i => $parameter) { |
|
| 218 | - if ($i >= $namedArgsBegin) { |
|
| 217 | + foreach ($parameters as $i => $parameter){ |
|
| 218 | + if ($i >= $namedArgsBegin){ |
|
| 219 | 219 | break; |
| 220 | 220 | } |
| 221 | - if ($parameter->getName() === $badArgName) { |
|
| 221 | + if ($parameter->getName() === $badArgName){ |
|
| 222 | 222 | // The named argument overwrites a positional argument. |
| 223 | 223 | $message = \sprintf(self::ERROR_OVERWRITE_ARGUMENT, $badArgName); |
| 224 | 224 | throw new \BadMethodCallException($message); |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | // Special handling if a variadic parameter is present. |
| 229 | - if ($variadicParameter !== null) { |
|
| 229 | + if ($variadicParameter !== null){ |
|
| 230 | 230 | // The last parameter is variadic. |
| 231 | 231 | // Since PHP 8+, variadic parameters can consume named arguments. |
| 232 | 232 | // However, this code only runs if PHP < 8. |
@@ -49,17 +49,22 @@ discard block |
||
| 49 | 49 | */ |
| 50 | 50 | public function instantiate(\ReflectionClass $attr, array $arguments, \Reflector $context = null): object |
| 51 | 51 | { |
| 52 | - if ($this->isNamedArgumentsSupported()) { |
|
| 53 | - try { |
|
| 52 | + if ($this->isNamedArgumentsSupported()) |
|
| 53 | + { |
|
| 54 | + try |
|
| 55 | + { |
|
| 54 | 56 | return $attr->newInstanceArgs($arguments); |
| 55 | - } catch (\Throwable $e) { |
|
| 57 | + } |
|
| 58 | + catch (\Throwable $e) |
|
| 59 | + { |
|
| 56 | 60 | throw Exception::withLocation($e, $attr->getFileName(), $attr->getStartLine()); |
| 57 | 61 | } |
| 58 | 62 | } |
| 59 | 63 | |
| 60 | 64 | $constructor = $this->getConstructor($attr); |
| 61 | 65 | |
| 62 | - if ($constructor === null) { |
|
| 66 | + if ($constructor === null) |
|
| 67 | + { |
|
| 63 | 68 | return $attr->newInstanceWithoutConstructor(); |
| 64 | 69 | } |
| 65 | 70 | |
@@ -78,9 +83,12 @@ discard block |
||
| 78 | 83 | */ |
| 79 | 84 | private function resolveParameters(\ReflectionClass $ctx, \ReflectionMethod $constructor, array $arguments): array |
| 80 | 85 | { |
| 81 | - try { |
|
| 86 | + try |
|
| 87 | + { |
|
| 82 | 88 | return $this->doResolveParameters($ctx, $constructor, $arguments); |
| 83 | - } catch (\Throwable $e) { |
|
| 89 | + } |
|
| 90 | + catch (\Throwable $e) |
|
| 91 | + { |
|
| 84 | 92 | throw Exception::withLocation($e, $constructor->getFileName(), $constructor->getStartLine()); |
| 85 | 93 | } |
| 86 | 94 | } |
@@ -92,16 +100,20 @@ discard block |
||
| 92 | 100 | { |
| 93 | 101 | $namedArgsBegin = $this->analyzeKeys($arguments); |
| 94 | 102 | |
| 95 | - if ($namedArgsBegin === null) { |
|
| 103 | + if ($namedArgsBegin === null) |
|
| 104 | + { |
|
| 96 | 105 | // Only numeric / positional keys exist. |
| 97 | 106 | return $arguments; |
| 98 | 107 | } |
| 99 | 108 | |
| 100 | - if ($namedArgsBegin === 0) { |
|
| 109 | + if ($namedArgsBegin === 0) |
|
| 110 | + { |
|
| 101 | 111 | // Only named keys exist. |
| 102 | 112 | $passed = []; |
| 103 | 113 | $named = $arguments; |
| 104 | - } else { |
|
| 114 | + } |
|
| 115 | + else |
|
| 116 | + { |
|
| 105 | 117 | // Numeric/positional keys followed by named keys. |
| 106 | 118 | // No need to preserve numeric keys. |
| 107 | 119 | $passed = array_slice($arguments, 0, $namedArgsBegin); |
@@ -135,11 +147,14 @@ discard block |
||
| 135 | 147 | $arguments = \array_merge($arguments); |
| 136 | 148 | |
| 137 | 149 | $i = 0; |
| 138 | - foreach ($arguments as $k => $_) { |
|
| 139 | - if ($k !== $i) { |
|
| 150 | + foreach ($arguments as $k => $_) |
|
| 151 | + { |
|
| 152 | + if ($k !== $i) |
|
| 153 | + { |
|
| 140 | 154 | // This must be a string key. |
| 141 | 155 | // Any further numeric keys are illegal. |
| 142 | - if (\array_key_exists($i, $arguments)) { |
|
| 156 | + if (\array_key_exists($i, $arguments)) |
|
| 157 | + { |
|
| 143 | 158 | throw new \BadMethodCallException(self::ERROR_POSITIONAL_AFTER_NAMED); |
| 144 | 159 | } |
| 145 | 160 | return $i; |
@@ -175,25 +190,34 @@ discard block |
||
| 175 | 190 | ): array { |
| 176 | 191 | // Analyze parameters. |
| 177 | 192 | $n = count($parameters); |
| 178 | - if ($n > 0 && end($parameters)->isVariadic()) { |
|
| 193 | + if ($n > 0 && end($parameters)->isVariadic()) |
|
| 194 | + { |
|
| 179 | 195 | $variadicParameter = end($parameters); |
| 180 | 196 | // Don't include the variadic parameter in the mapping process. |
| 181 | 197 | --$n; |
| 182 | - } else { |
|
| 198 | + } |
|
| 199 | + else |
|
| 200 | + { |
|
| 183 | 201 | $variadicParameter = null; |
| 184 | 202 | } |
| 185 | 203 | |
| 186 | 204 | // Process parameters that are not already filled with positional args. |
| 187 | 205 | // This loop will do nothing if $namedArgsBegin >= $n. That's ok. |
| 188 | - for ($i = $namedArgsBegin; $i < $n; ++$i) { |
|
| 206 | + for ($i = $namedArgsBegin; $i < $n; ++$i) |
|
| 207 | + { |
|
| 189 | 208 | $parameter = $parameters[$i]; |
| 190 | 209 | $k = $parameter->getName(); |
| 191 | - if (array_key_exists($k, $named)) { |
|
| 210 | + if (array_key_exists($k, $named)) |
|
| 211 | + { |
|
| 192 | 212 | $passed[] = $named[$k]; |
| 193 | 213 | unset($named[$k]); |
| 194 | - } elseif ($parameter->isDefaultValueAvailable()) { |
|
| 214 | + } |
|
| 215 | + elseif ($parameter->isDefaultValueAvailable()) |
|
| 216 | + { |
|
| 195 | 217 | $passed[] = $parameter->getDefaultValue(); |
| 196 | - } else { |
|
| 218 | + } |
|
| 219 | + else |
|
| 220 | + { |
|
| 197 | 221 | $message = \vsprintf(self::ERROR_ARGUMENT_NOT_PASSED, [ |
| 198 | 222 | $ctx->getName(), |
| 199 | 223 | $parameter->getPosition() + 1, |
@@ -204,7 +228,8 @@ discard block |
||
| 204 | 228 | } |
| 205 | 229 | } |
| 206 | 230 | |
| 207 | - if ($named === []) { |
|
| 231 | + if ($named === []) |
|
| 232 | + { |
|
| 208 | 233 | // No unknown argument names exist. |
| 209 | 234 | return $passed; |
| 210 | 235 | } |
@@ -214,11 +239,14 @@ discard block |
||
| 214 | 239 | $badArgName = key($named); |
| 215 | 240 | |
| 216 | 241 | // Check collision with positional arguments. |
| 217 | - foreach ($parameters as $i => $parameter) { |
|
| 218 | - if ($i >= $namedArgsBegin) { |
|
| 242 | + foreach ($parameters as $i => $parameter) |
|
| 243 | + { |
|
| 244 | + if ($i >= $namedArgsBegin) |
|
| 245 | + { |
|
| 219 | 246 | break; |
| 220 | 247 | } |
| 221 | - if ($parameter->getName() === $badArgName) { |
|
| 248 | + if ($parameter->getName() === $badArgName) |
|
| 249 | + { |
|
| 222 | 250 | // The named argument overwrites a positional argument. |
| 223 | 251 | $message = \sprintf(self::ERROR_OVERWRITE_ARGUMENT, $badArgName); |
| 224 | 252 | throw new \BadMethodCallException($message); |
@@ -226,7 +254,8 @@ discard block |
||
| 226 | 254 | } |
| 227 | 255 | |
| 228 | 256 | // Special handling if a variadic parameter is present. |
| 229 | - if ($variadicParameter !== null) { |
|
| 257 | + if ($variadicParameter !== null) |
|
| 258 | + { |
|
| 230 | 259 | // The last parameter is variadic. |
| 231 | 260 | // Since PHP 8+, variadic parameters can consume named arguments. |
| 232 | 261 | // However, this code only runs if PHP < 8. |
@@ -73,23 +73,23 @@ discard block |
||
| 73 | 73 | |
| 74 | 74 | public function testUnknownSequentialAfterNamed() |
| 75 | 75 | { |
| 76 | - if (PHP_VERSION_ID < 80000) { |
|
| 76 | + if (PHP_VERSION_ID < 80000){ |
|
| 77 | 77 | $this->expectException(\BadMethodCallException::class); |
| 78 | - } else { |
|
| 78 | + }else{ |
|
| 79 | 79 | $this->expectException(\Error::class); |
| 80 | 80 | } |
| 81 | 81 | /* @see NamedArgumentsInstantiator::ERROR_POSITIONAL_AFTER_NAMED */ |
| 82 | 82 | $this->expectExceptionMessageEquals('Cannot use positional argument after named argument'); |
| 83 | 83 | |
| 84 | - try { |
|
| 84 | + try{ |
|
| 85 | 85 | $this->new($class = NamedArgumentConstructorFixture::class, [ |
| 86 | 86 | 'a' => 'A', |
| 87 | 87 | 5 => 'five', |
| 88 | 88 | ]); |
| 89 | - } catch (\Throwable $e) { |
|
| 90 | - if (PHP_VERSION_ID < 80000) { |
|
| 89 | + }catch (\Throwable $e){ |
|
| 90 | + if (PHP_VERSION_ID < 80000){ |
|
| 91 | 91 | self::assertExceptionSource($e, $class, 'function __construct'); |
| 92 | - } else { |
|
| 92 | + }else{ |
|
| 93 | 93 | self::assertExceptionSource($e, $class, 'class '); |
| 94 | 94 | } |
| 95 | 95 | throw $e; |
@@ -98,9 +98,9 @@ discard block |
||
| 98 | 98 | |
| 99 | 99 | public function testKnownSequentialAfterNamed() |
| 100 | 100 | { |
| 101 | - if (PHP_VERSION_ID < 80000) { |
|
| 101 | + if (PHP_VERSION_ID < 80000){ |
|
| 102 | 102 | $this->expectException(\BadMethodCallException::class); |
| 103 | - } else { |
|
| 103 | + }else{ |
|
| 104 | 104 | $this->expectException(\Error::class); |
| 105 | 105 | } |
| 106 | 106 | /* @see NamedArgumentsInstantiator::ERROR_POSITIONAL_AFTER_NAMED */ |
@@ -123,15 +123,15 @@ discard block |
||
| 123 | 123 | ) |
| 124 | 124 | ); |
| 125 | 125 | |
| 126 | - try { |
|
| 126 | + try{ |
|
| 127 | 127 | $this->new($class = NamedRequiredArgumentConstructorFixture::class, [ |
| 128 | 128 | 'a', |
| 129 | 129 | 'c' => 'C', |
| 130 | 130 | ]); |
| 131 | - } catch (\Throwable $e) { |
|
| 132 | - if (PHP_VERSION_ID < 80000) { |
|
| 131 | + }catch (\Throwable $e){ |
|
| 132 | + if (PHP_VERSION_ID < 80000){ |
|
| 133 | 133 | self::assertExceptionSource($e, $class, 'function __construct'); |
| 134 | - } else { |
|
| 134 | + }else{ |
|
| 135 | 135 | self::assertExceptionSource($e, $class, 'class '); |
| 136 | 136 | } |
| 137 | 137 | throw $e; |
@@ -140,22 +140,22 @@ discard block |
||
| 140 | 140 | |
| 141 | 141 | public function testUnknownArg() |
| 142 | 142 | { |
| 143 | - if (PHP_VERSION_ID < 80000) { |
|
| 143 | + if (PHP_VERSION_ID < 80000){ |
|
| 144 | 144 | $this->expectException(\BadMethodCallException::class); |
| 145 | - } else { |
|
| 145 | + }else{ |
|
| 146 | 146 | $this->expectException(\Error::class); |
| 147 | 147 | } |
| 148 | 148 | /* @see NamedArgumentsInstantiator::ERROR_UNKNOWN_ARGUMENT */ |
| 149 | 149 | $this->expectExceptionMessageEquals('Unknown named parameter $d'); |
| 150 | 150 | |
| 151 | - try { |
|
| 151 | + try{ |
|
| 152 | 152 | $this->new($class = NamedArgumentConstructorFixture::class, [ |
| 153 | 153 | 'd' => 'D', |
| 154 | 154 | ]); |
| 155 | - } catch (\Throwable $e) { |
|
| 156 | - if (PHP_VERSION_ID < 80000) { |
|
| 155 | + }catch (\Throwable $e){ |
|
| 156 | + if (PHP_VERSION_ID < 80000){ |
|
| 157 | 157 | self::assertExceptionSource($e, $class, 'function __construct'); |
| 158 | - } else { |
|
| 158 | + }else{ |
|
| 159 | 159 | self::assertExceptionSource($e, $class, 'class '); |
| 160 | 160 | } |
| 161 | 161 | throw $e; |
@@ -164,9 +164,9 @@ discard block |
||
| 164 | 164 | |
| 165 | 165 | public function testOverwriteArg() |
| 166 | 166 | { |
| 167 | - if (PHP_VERSION_ID < 80000) { |
|
| 167 | + if (PHP_VERSION_ID < 80000){ |
|
| 168 | 168 | $this->expectException(\BadMethodCallException::class); |
| 169 | - } else { |
|
| 169 | + }else{ |
|
| 170 | 170 | $this->expectException(\Error::class); |
| 171 | 171 | } |
| 172 | 172 | /* @see NamedArgumentsInstantiator::ERROR_OVERWRITE_ARGUMENT */ |
@@ -195,9 +195,9 @@ discard block |
||
| 195 | 195 | |
| 196 | 196 | public function testVariadicPositionalAfterNamed() |
| 197 | 197 | { |
| 198 | - if (PHP_VERSION_ID < 80000) { |
|
| 198 | + if (PHP_VERSION_ID < 80000){ |
|
| 199 | 199 | $this->expectException(\BadMethodCallException::class); |
| 200 | - } else { |
|
| 200 | + }else{ |
|
| 201 | 201 | $this->expectException(\Error::class); |
| 202 | 202 | } |
| 203 | 203 | /* @see NamedArgumentsInstantiator::ERROR_POSITIONAL_AFTER_NAMED */ |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | |
| 214 | 214 | public function testVariadicMixed() |
| 215 | 215 | { |
| 216 | - if (PHP_VERSION_ID < 80000) { |
|
| 216 | + if (PHP_VERSION_ID < 80000){ |
|
| 217 | 217 | $this->expectException(\BadMethodCallException::class); |
| 218 | 218 | /* @see NamedArgumentsInstantiator::ERROR_NAMED_ARG_TO_VARIADIC */ |
| 219 | 219 | $this->expectExceptionMessageEquals('Cannot pass named argument $x to variadic parameter $args in PHP < 8'); |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | |
| 235 | 235 | public function testVariadicNamed() |
| 236 | 236 | { |
| 237 | - if (PHP_VERSION_ID < 80000) { |
|
| 237 | + if (PHP_VERSION_ID < 80000){ |
|
| 238 | 238 | $this->expectException(\BadMethodCallException::class); |
| 239 | 239 | /* @see NamedArgumentsInstantiator::ERROR_NAMED_ARG_TO_VARIADIC */ |
| 240 | 240 | $this->expectExceptionMessageEquals('Cannot pass named argument $x to variadic parameter $args in PHP < 8'); |
@@ -73,23 +73,32 @@ discard block |
||
| 73 | 73 | |
| 74 | 74 | public function testUnknownSequentialAfterNamed() |
| 75 | 75 | { |
| 76 | - if (PHP_VERSION_ID < 80000) { |
|
| 76 | + if (PHP_VERSION_ID < 80000) |
|
| 77 | + { |
|
| 77 | 78 | $this->expectException(\BadMethodCallException::class); |
| 78 | - } else { |
|
| 79 | + } |
|
| 80 | + else |
|
| 81 | + { |
|
| 79 | 82 | $this->expectException(\Error::class); |
| 80 | 83 | } |
| 81 | 84 | /* @see NamedArgumentsInstantiator::ERROR_POSITIONAL_AFTER_NAMED */ |
| 82 | 85 | $this->expectExceptionMessageEquals('Cannot use positional argument after named argument'); |
| 83 | 86 | |
| 84 | - try { |
|
| 87 | + try |
|
| 88 | + { |
|
| 85 | 89 | $this->new($class = NamedArgumentConstructorFixture::class, [ |
| 86 | 90 | 'a' => 'A', |
| 87 | 91 | 5 => 'five', |
| 88 | 92 | ]); |
| 89 | - } catch (\Throwable $e) { |
|
| 90 | - if (PHP_VERSION_ID < 80000) { |
|
| 93 | + } |
|
| 94 | + catch (\Throwable $e) |
|
| 95 | + { |
|
| 96 | + if (PHP_VERSION_ID < 80000) |
|
| 97 | + { |
|
| 91 | 98 | self::assertExceptionSource($e, $class, 'function __construct'); |
| 92 | - } else { |
|
| 99 | + } |
|
| 100 | + else |
|
| 101 | + { |
|
| 93 | 102 | self::assertExceptionSource($e, $class, 'class '); |
| 94 | 103 | } |
| 95 | 104 | throw $e; |
@@ -98,9 +107,12 @@ discard block |
||
| 98 | 107 | |
| 99 | 108 | public function testKnownSequentialAfterNamed() |
| 100 | 109 | { |
| 101 | - if (PHP_VERSION_ID < 80000) { |
|
| 110 | + if (PHP_VERSION_ID < 80000) |
|
| 111 | + { |
|
| 102 | 112 | $this->expectException(\BadMethodCallException::class); |
| 103 | - } else { |
|
| 113 | + } |
|
| 114 | + else |
|
| 115 | + { |
|
| 104 | 116 | $this->expectException(\Error::class); |
| 105 | 117 | } |
| 106 | 118 | /* @see NamedArgumentsInstantiator::ERROR_POSITIONAL_AFTER_NAMED */ |
@@ -123,15 +135,21 @@ discard block |
||
| 123 | 135 | ) |
| 124 | 136 | ); |
| 125 | 137 | |
| 126 | - try { |
|
| 138 | + try |
|
| 139 | + { |
|
| 127 | 140 | $this->new($class = NamedRequiredArgumentConstructorFixture::class, [ |
| 128 | 141 | 'a', |
| 129 | 142 | 'c' => 'C', |
| 130 | 143 | ]); |
| 131 | - } catch (\Throwable $e) { |
|
| 132 | - if (PHP_VERSION_ID < 80000) { |
|
| 144 | + } |
|
| 145 | + catch (\Throwable $e) |
|
| 146 | + { |
|
| 147 | + if (PHP_VERSION_ID < 80000) |
|
| 148 | + { |
|
| 133 | 149 | self::assertExceptionSource($e, $class, 'function __construct'); |
| 134 | - } else { |
|
| 150 | + } |
|
| 151 | + else |
|
| 152 | + { |
|
| 135 | 153 | self::assertExceptionSource($e, $class, 'class '); |
| 136 | 154 | } |
| 137 | 155 | throw $e; |
@@ -140,22 +158,31 @@ discard block |
||
| 140 | 158 | |
| 141 | 159 | public function testUnknownArg() |
| 142 | 160 | { |
| 143 | - if (PHP_VERSION_ID < 80000) { |
|
| 161 | + if (PHP_VERSION_ID < 80000) |
|
| 162 | + { |
|
| 144 | 163 | $this->expectException(\BadMethodCallException::class); |
| 145 | - } else { |
|
| 164 | + } |
|
| 165 | + else |
|
| 166 | + { |
|
| 146 | 167 | $this->expectException(\Error::class); |
| 147 | 168 | } |
| 148 | 169 | /* @see NamedArgumentsInstantiator::ERROR_UNKNOWN_ARGUMENT */ |
| 149 | 170 | $this->expectExceptionMessageEquals('Unknown named parameter $d'); |
| 150 | 171 | |
| 151 | - try { |
|
| 172 | + try |
|
| 173 | + { |
|
| 152 | 174 | $this->new($class = NamedArgumentConstructorFixture::class, [ |
| 153 | 175 | 'd' => 'D', |
| 154 | 176 | ]); |
| 155 | - } catch (\Throwable $e) { |
|
| 156 | - if (PHP_VERSION_ID < 80000) { |
|
| 177 | + } |
|
| 178 | + catch (\Throwable $e) |
|
| 179 | + { |
|
| 180 | + if (PHP_VERSION_ID < 80000) |
|
| 181 | + { |
|
| 157 | 182 | self::assertExceptionSource($e, $class, 'function __construct'); |
| 158 | - } else { |
|
| 183 | + } |
|
| 184 | + else |
|
| 185 | + { |
|
| 159 | 186 | self::assertExceptionSource($e, $class, 'class '); |
| 160 | 187 | } |
| 161 | 188 | throw $e; |
@@ -164,9 +191,12 @@ discard block |
||
| 164 | 191 | |
| 165 | 192 | public function testOverwriteArg() |
| 166 | 193 | { |
| 167 | - if (PHP_VERSION_ID < 80000) { |
|
| 194 | + if (PHP_VERSION_ID < 80000) |
|
| 195 | + { |
|
| 168 | 196 | $this->expectException(\BadMethodCallException::class); |
| 169 | - } else { |
|
| 197 | + } |
|
| 198 | + else |
|
| 199 | + { |
|
| 170 | 200 | $this->expectException(\Error::class); |
| 171 | 201 | } |
| 172 | 202 | /* @see NamedArgumentsInstantiator::ERROR_OVERWRITE_ARGUMENT */ |
@@ -195,9 +225,12 @@ discard block |
||
| 195 | 225 | |
| 196 | 226 | public function testVariadicPositionalAfterNamed() |
| 197 | 227 | { |
| 198 | - if (PHP_VERSION_ID < 80000) { |
|
| 228 | + if (PHP_VERSION_ID < 80000) |
|
| 229 | + { |
|
| 199 | 230 | $this->expectException(\BadMethodCallException::class); |
| 200 | - } else { |
|
| 231 | + } |
|
| 232 | + else |
|
| 233 | + { |
|
| 201 | 234 | $this->expectException(\Error::class); |
| 202 | 235 | } |
| 203 | 236 | /* @see NamedArgumentsInstantiator::ERROR_POSITIONAL_AFTER_NAMED */ |
@@ -213,7 +246,8 @@ discard block |
||
| 213 | 246 | |
| 214 | 247 | public function testVariadicMixed() |
| 215 | 248 | { |
| 216 | - if (PHP_VERSION_ID < 80000) { |
|
| 249 | + if (PHP_VERSION_ID < 80000) |
|
| 250 | + { |
|
| 217 | 251 | $this->expectException(\BadMethodCallException::class); |
| 218 | 252 | /* @see NamedArgumentsInstantiator::ERROR_NAMED_ARG_TO_VARIADIC */ |
| 219 | 253 | $this->expectExceptionMessageEquals('Cannot pass named argument $x to variadic parameter $args in PHP < 8'); |
@@ -234,7 +268,8 @@ discard block |
||
| 234 | 268 | |
| 235 | 269 | public function testVariadicNamed() |
| 236 | 270 | { |
| 237 | - if (PHP_VERSION_ID < 80000) { |
|
| 271 | + if (PHP_VERSION_ID < 80000) |
|
| 272 | + { |
|
| 238 | 273 | $this->expectException(\BadMethodCallException::class); |
| 239 | 274 | /* @see NamedArgumentsInstantiator::ERROR_NAMED_ARG_TO_VARIADIC */ |
| 240 | 275 | $this->expectExceptionMessageEquals('Cannot pass named argument $x to variadic parameter $args in PHP < 8'); |