diff --git a/DebugClassLoader.php b/DebugClassLoader.php index 69c28c1..1b4aae1 100644 --- a/DebugClassLoader.php +++ b/DebugClassLoader.php @@ -21,6 +21,7 @@ use Prophecy\Prophecy\ProphecySubjectInterface; use ProxyManager\Proxy\ProxyInterface; use Symfony\Component\ErrorHandler\Internal\TentativeTypes; +use Symfony\Component\HttpClient\HttplugClient; use Symfony\Component\VarExporter\LazyObjectInterface; /** @@ -421,7 +422,9 @@ public function checkAnnotations(\ReflectionClass $refl, string $class): array if (!isset(self::$checkedClasses[$use])) { $this->checkClass($use); } - if (isset(self::$deprecated[$use]) && strncmp($vendor, str_replace('_', '\\', $use), $vendorLen) && !isset(self::$deprecated[$class])) { + if (isset(self::$deprecated[$use]) && strncmp($vendor, str_replace('_', '\\', $use), $vendorLen) && !isset(self::$deprecated[$class]) + && !(HttplugClient::class === $class && \in_array($use, [\Http\Message\RequestFactory::class, \Http\Message\StreamFactory::class, \Http\Message\UriFactory::class], true)) + ) { $type = class_exists($class, false) ? 'class' : (interface_exists($class, false) ? 'interface' : 'trait'); $verb = class_exists($use, false) || interface_exists($class, false) ? 'extends' : (interface_exists($use, false) ? 'implements' : 'uses'); @@ -1129,7 +1132,20 @@ private function fixReturnStatements(\ReflectionMethod $method, string $returnTy } $end = $method->isGenerator() ? $i : $method->getEndLine(); + $inClosure = false; + $braces = 0; for (; $i < $end; ++$i) { + if (!$inClosure) { + $inClosure = str_contains($code[$i], 'function ('); + } + + if ($inClosure) { + $braces += substr_count($code[$i], '{') - substr_count($code[$i], '}'); + $inClosure = $braces > 0; + + continue; + } + if ('void' === $returnType) { $fixedCode[$i] = str_replace(' return null;', ' return;', $code[$i]); } elseif ('mixed' === $returnType || '?' === $returnType[0]) { diff --git a/ErrorRenderer/SerializerErrorRenderer.php b/ErrorRenderer/SerializerErrorRenderer.php index 8130b2e..1f286b7 100644 --- a/ErrorRenderer/SerializerErrorRenderer.php +++ b/ErrorRenderer/SerializerErrorRenderer.php @@ -44,7 +44,7 @@ public function __construct(SerializerInterface $serializer, string|callable $fo public function render(\Throwable $exception): FlattenException { - $headers = []; + $headers = ['Vary' => 'Accept']; $debug = \is_bool($this->debug) ? $this->debug : ($this->debug)($exception); if ($debug) { $headers['X-Debug-Exception'] = rawurlencode($exception->getMessage()); @@ -55,19 +55,17 @@ public function render(\Throwable $exception): FlattenException try { $format = \is_string($this->format) ? $this->format : ($this->format)($flattenException); - $headers = [ - 'Content-Type' => Request::getMimeTypes($format)[0] ?? $format, - 'Vary' => 'Accept', - ]; + $headers['Content-Type'] = Request::getMimeTypes($format)[0] ?? $format; - return $flattenException->setAsString($this->serializer->serialize($flattenException, $format, [ + $flattenException->setAsString($this->serializer->serialize($flattenException, $format, [ 'exception' => $exception, 'debug' => $debug, - ])) - ->setHeaders($flattenException->getHeaders() + $headers); + ])); } catch (NotEncodableValueException) { - return $this->fallbackErrorRenderer->render($exception); + $flattenException = $this->fallbackErrorRenderer->render($exception); } + + return $flattenException->setHeaders($flattenException->getHeaders() + $headers); } public static function getPreferredFormat(RequestStack $requestStack): \Closure diff --git a/LICENSE b/LICENSE index 5c7ba05..f37c76b 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2019-2023 Fabien Potencier +Copyright (c) 2019-present Fabien Potencier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Resources/views/error.html.php b/Resources/views/error.html.php index fccbc08..a1624ea 100644 --- a/Resources/views/error.html.php +++ b/Resources/views/error.html.php @@ -1,5 +1,5 @@ - + diff --git a/Tests/DebugClassLoaderTest.php b/Tests/DebugClassLoaderTest.php index ab2ea41..edb5851 100644 --- a/Tests/DebugClassLoaderTest.php +++ b/Tests/DebugClassLoaderTest.php @@ -140,7 +140,7 @@ class_exists('Test\\'.__NAMESPACE__.'\\'.$class, true); $this->assertSame($xError, $lastError); } - public function provideDeprecatedSuper(): array + public static function provideDeprecatedSuper(): array { return [ ['DeprecatedInterfaceClass', 'DeprecatedInterface', 'implements'], diff --git a/Tests/ErrorEnhancer/ClassNotFoundErrorEnhancerTest.php b/Tests/ErrorEnhancer/ClassNotFoundErrorEnhancerTest.php index 1ca2f16..72ee199 100644 --- a/Tests/ErrorEnhancer/ClassNotFoundErrorEnhancerTest.php +++ b/Tests/ErrorEnhancer/ClassNotFoundErrorEnhancerTest.php @@ -72,7 +72,7 @@ public function testEnhance(string $originalMessage, string $enhancedMessage, $a $this->assertSame($expectedLine, $error->getLine()); } - public function provideClassNotFoundData() + public static function provideClassNotFoundData() { $autoloader = new ComposerClassLoader(); $autoloader->add('Symfony\Component\ErrorHandler\Error\\', realpath(__DIR__.'/../../Error')); diff --git a/Tests/ErrorEnhancer/UndefinedFunctionErrorEnhancerTest.php b/Tests/ErrorEnhancer/UndefinedFunctionErrorEnhancerTest.php index fe7d537..547e333 100644 --- a/Tests/ErrorEnhancer/UndefinedFunctionErrorEnhancerTest.php +++ b/Tests/ErrorEnhancer/UndefinedFunctionErrorEnhancerTest.php @@ -34,7 +34,7 @@ public function testEnhance(string $originalMessage, string $enhancedMessage) $this->assertSame($expectedLine, $error->getLine()); } - public function provideUndefinedFunctionData() + public static function provideUndefinedFunctionData() { return [ [ diff --git a/Tests/ErrorEnhancer/UndefinedMethodErrorEnhancerTest.php b/Tests/ErrorEnhancer/UndefinedMethodErrorEnhancerTest.php index b31c6c2..f417200 100644 --- a/Tests/ErrorEnhancer/UndefinedMethodErrorEnhancerTest.php +++ b/Tests/ErrorEnhancer/UndefinedMethodErrorEnhancerTest.php @@ -33,7 +33,7 @@ public function testEnhance(string $originalMessage, string $enhancedMessage) $this->assertSame($expectedLine, $error->getLine()); } - public function provideUndefinedMethodData() + public static function provideUndefinedMethodData() { return [ [ diff --git a/Tests/ErrorHandlerTest.php b/Tests/ErrorHandlerTest.php index a45e8e1..3926b73 100644 --- a/Tests/ErrorHandlerTest.php +++ b/Tests/ErrorHandlerTest.php @@ -402,7 +402,7 @@ public function testHandleException(string $expectedMessage, \Throwable $excepti } } - public function handleExceptionProvider(): array + public static function handleExceptionProvider(): array { return [ ['Uncaught Exception: foo', new \Exception('foo')], @@ -602,7 +602,7 @@ public function testErrorHandlerWhenLogging(bool $previousHandlerWasDefined, boo } } - public function errorHandlerWhenLoggingProvider(): iterable + public static function errorHandlerWhenLoggingProvider(): iterable { foreach ([false, true] as $previousHandlerWasDefined) { foreach ([false, true] as $loggerSetsAnotherHandler) { diff --git a/Tests/ErrorRenderer/HtmlErrorRendererTest.php b/Tests/ErrorRenderer/HtmlErrorRendererTest.php index f292d0f..6680b95 100644 --- a/Tests/ErrorRenderer/HtmlErrorRendererTest.php +++ b/Tests/ErrorRenderer/HtmlErrorRendererTest.php @@ -24,7 +24,7 @@ public function testRender(\Throwable $exception, HtmlErrorRenderer $errorRender $this->assertStringMatchesFormat($expected, $errorRenderer->render($exception)->getAsString()); } - public function getRenderData(): iterable + public static function getRenderData(): iterable { $expectedDebug = << @@ -37,7 +37,7 @@ public function getRenderData(): iterable $expectedNonDebug = << - + %AAn Error Occurred: Internal Server Error %A

The server returned a "500 Internal Server Error".

%A HTML; diff --git a/Tests/Exception/FlattenExceptionTest.php b/Tests/Exception/FlattenExceptionTest.php index 298fb67..b1fadb4 100644 --- a/Tests/Exception/FlattenExceptionTest.php +++ b/Tests/Exception/FlattenExceptionTest.php @@ -226,7 +226,7 @@ public function testCreate() ); } - public function flattenDataProvider(): array + public static function flattenDataProvider(): array { return [ [new \Exception('test', 123), 'Exception'], @@ -234,7 +234,7 @@ public function flattenDataProvider(): array ]; } - public function stringAndIntDataProvider(): array + public static function stringAndIntDataProvider(): array { return [ [new \Exception('test1', 123)],