From 05fe553666cb1fc68f55c47b57fa807073ec1ed6 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 23 Aug 2019 13:30:52 +0200 Subject: [PATCH] [HttpKernel] Fix return type declarations --- .../Tests/Functional/ProfilerTest.php | 6 +++--- src/Symfony/Component/BrowserKit/Request.php | 2 +- .../DependencyInjection/Container.php | 2 -- .../Dumper/DumperInterface.php | 4 +--- .../Controller/ControllerResolver.php | 18 ++++++++++++------ .../DataCollector/ConfigDataCollector.php | 2 +- .../DataCollector/ExceptionDataCollector.php | 2 +- .../DataCollector/LoggerDataCollector.php | 5 ----- .../DataCollector/TimeDataCollector.php | 2 +- .../HttpKernel/HttpCache/AbstractSurrogate.php | 2 +- .../Component/HttpKernel/HttpCache/Ssi.php | 2 +- src/Symfony/Component/HttpKernel/Kernel.php | 4 ++-- .../Component/HttpKernel/KernelInterface.php | 2 +- .../Component/HttpKernel/Profiler/Profile.php | 11 +++++++---- .../Component/HttpKernel/Profiler/Profiler.php | 6 +++--- .../HttpKernel/Tests/Bundle/BundleTest.php | 3 +++ .../DataCollector/LoggerDataCollectorTest.php | 2 +- .../DataCollector/TimeDataCollectorTest.php | 2 +- .../Component/HttpKernel/Tests/KernelTest.php | 4 ++-- 19 files changed, 42 insertions(+), 39 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ProfilerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ProfilerTest.php index 7ee42cdd17..35c2e63b7e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ProfilerTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ProfilerTest.php @@ -24,16 +24,16 @@ class ProfilerTest extends AbstractWebTestCase } $client->request('GET', '/profiler'); - $this->assertFalse($client->getProfile()); + $this->assertNull($client->getProfile()); // enable the profiler for the next request $client->enableProfiler(); - $this->assertFalse($client->getProfile()); + $this->assertNull($client->getProfile()); $client->request('GET', '/profiler'); $this->assertIsObject($client->getProfile()); $client->request('GET', '/profiler'); - $this->assertFalse($client->getProfile()); + $this->assertNull($client->getProfile()); } public function getConfigs() diff --git a/src/Symfony/Component/BrowserKit/Request.php b/src/Symfony/Component/BrowserKit/Request.php index 599652bf34..6e0cb08ccb 100644 --- a/src/Symfony/Component/BrowserKit/Request.php +++ b/src/Symfony/Component/BrowserKit/Request.php @@ -107,7 +107,7 @@ class Request /** * Gets the request raw body data. * - * @return string The request raw body data + * @return string|null The request raw body data */ public function getContent() { diff --git a/src/Symfony/Component/DependencyInjection/Container.php b/src/Symfony/Component/DependencyInjection/Container.php index ab69579adb..ad06c7e245 100644 --- a/src/Symfony/Component/DependencyInjection/Container.php +++ b/src/Symfony/Component/DependencyInjection/Container.php @@ -444,8 +444,6 @@ class Container implements ResettableContainerInterface /** * Creates a service by requiring its factory file. - * - * @return object The service created by the file */ protected function load($file) { diff --git a/src/Symfony/Component/DependencyInjection/Dumper/DumperInterface.php b/src/Symfony/Component/DependencyInjection/Dumper/DumperInterface.php index 1ea775ddfe..8abc19250f 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/DumperInterface.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/DumperInterface.php @@ -21,9 +21,7 @@ interface DumperInterface /** * Dumps the service container. * - * @param array $options An array of options - * - * @return string The representation of the service container + * @return string|array The representation of the service container */ public function dump(array $options = []); } diff --git a/src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php b/src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php index bce2f8df70..c981642fee 100644 --- a/src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php +++ b/src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php @@ -85,10 +85,10 @@ class ControllerResolver implements ArgumentResolverInterface, ControllerResolve } } - $callable = $this->createController($controller); - - if (!\is_callable($callable)) { - throw new \InvalidArgumentException(sprintf('The controller for URI "%s" is not callable. %s', $request->getPathInfo(), $this->getControllerError($callable))); + try { + $callable = $this->createController($controller); + } catch (\InvalidArgumentException $e) { + throw new \InvalidArgumentException(sprintf('The controller for URI "%s" is not callable. %s', $request->getPathInfo(), $e->getMessage())); } return $callable; @@ -165,7 +165,7 @@ class ControllerResolver implements ArgumentResolverInterface, ControllerResolve * * @return callable A PHP callable * - * @throws \InvalidArgumentException + * @throws \InvalidArgumentException When the controller cannot be created */ protected function createController($controller) { @@ -179,7 +179,13 @@ class ControllerResolver implements ArgumentResolverInterface, ControllerResolve throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class)); } - return [$this->instantiateController($class), $method]; + $controller = [$this->instantiateController($class), $method]; + + if (!\is_callable($controller)) { + throw new \InvalidArgumentException($this->getControllerError($controller)); + } + + return $controller; } /** diff --git a/src/Symfony/Component/HttpKernel/DataCollector/ConfigDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/ConfigDataCollector.php index 626c1cc695..96d60c003f 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/ConfigDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/ConfigDataCollector.php @@ -119,7 +119,7 @@ class ConfigDataCollector extends DataCollector implements LateDataCollectorInte /** * Gets the token. * - * @return string The token + * @return string|null The token */ public function getToken() { diff --git a/src/Symfony/Component/HttpKernel/DataCollector/ExceptionDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/ExceptionDataCollector.php index c76e7f45bd..f9be5bddff 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/ExceptionDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/ExceptionDataCollector.php @@ -55,7 +55,7 @@ class ExceptionDataCollector extends DataCollector /** * Gets the exception. * - * @return \Exception The exception + * @return \Exception|FlattenException */ public function getException() { diff --git a/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php index a8dda9f671..99a9cf23e8 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php @@ -72,11 +72,6 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte } } - /** - * Gets the logs. - * - * @return array An array of logs - */ public function getLogs() { return isset($this->data['logs']) ? $this->data['logs'] : []; diff --git a/src/Symfony/Component/HttpKernel/DataCollector/TimeDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/TimeDataCollector.php index d070e83868..cb490c2bb3 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/TimeDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/TimeDataCollector.php @@ -132,7 +132,7 @@ class TimeDataCollector extends DataCollector implements LateDataCollectorInterf /** * Gets the request time. * - * @return int The time + * @return float */ public function getStartTime() { diff --git a/src/Symfony/Component/HttpKernel/HttpCache/AbstractSurrogate.php b/src/Symfony/Component/HttpKernel/HttpCache/AbstractSurrogate.php index 1d62f32e67..9b4541793f 100644 --- a/src/Symfony/Component/HttpKernel/HttpCache/AbstractSurrogate.php +++ b/src/Symfony/Component/HttpKernel/HttpCache/AbstractSurrogate.php @@ -110,7 +110,7 @@ abstract class AbstractSurrogate implements SurrogateInterface } } - return null; + return ''; } /** diff --git a/src/Symfony/Component/HttpKernel/HttpCache/Ssi.php b/src/Symfony/Component/HttpKernel/HttpCache/Ssi.php index 707abca5eb..40aac64f2a 100644 --- a/src/Symfony/Component/HttpKernel/HttpCache/Ssi.php +++ b/src/Symfony/Component/HttpKernel/HttpCache/Ssi.php @@ -95,6 +95,6 @@ class Ssi extends AbstractSurrogate // remove SSI/1.0 from the Surrogate-Control header $this->removeFromControl($response); - return null; + return $response; } } diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index a7d7977db4..80c0e8cceb 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -206,7 +206,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl /** * Gets a HTTP kernel from the container. * - * @return HttpKernel + * @return HttpKernelInterface */ protected function getHttpKernel() { @@ -425,7 +425,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl */ public function getStartTime() { - return $this->debug ? $this->startTime : -INF; + return $this->debug && null !== $this->startTime ? $this->startTime : -INF; } /** diff --git a/src/Symfony/Component/HttpKernel/KernelInterface.php b/src/Symfony/Component/HttpKernel/KernelInterface.php index d624d1219d..2445bbb43a 100644 --- a/src/Symfony/Component/HttpKernel/KernelInterface.php +++ b/src/Symfony/Component/HttpKernel/KernelInterface.php @@ -138,7 +138,7 @@ interface KernelInterface extends HttpKernelInterface, \Serializable /** * Gets the request start time (not available if debug is disabled). * - * @return int The request start timestamp + * @return float The request start timestamp */ public function getStartTime(); diff --git a/src/Symfony/Component/HttpKernel/Profiler/Profile.php b/src/Symfony/Component/HttpKernel/Profiler/Profile.php index c4490bc7a6..3665545d23 100644 --- a/src/Symfony/Component/HttpKernel/Profiler/Profile.php +++ b/src/Symfony/Component/HttpKernel/Profiler/Profile.php @@ -102,7 +102,7 @@ class Profile /** * Returns the IP. * - * @return string The IP + * @return string|null The IP */ public function getIp() { @@ -122,7 +122,7 @@ class Profile /** * Returns the request method. * - * @return string The request method + * @return string|null The request method */ public function getMethod() { @@ -137,13 +137,16 @@ class Profile /** * Returns the URL. * - * @return string The URL + * @return string|null The URL */ public function getUrl() { return $this->url; } + /** + * @param string $url + */ public function setUrl($url) { $this->url = $url; @@ -180,7 +183,7 @@ class Profile } /** - * @return int + * @return int|null */ public function getStatusCode() { diff --git a/src/Symfony/Component/HttpKernel/Profiler/Profiler.php b/src/Symfony/Component/HttpKernel/Profiler/Profiler.php index 0a078e7b98..c510afa3e0 100644 --- a/src/Symfony/Component/HttpKernel/Profiler/Profiler.php +++ b/src/Symfony/Component/HttpKernel/Profiler/Profiler.php @@ -65,12 +65,12 @@ class Profiler /** * Loads the Profile for the given Response. * - * @return Profile|false A Profile instance + * @return Profile|null A Profile instance */ public function loadProfileFromResponse(Response $response) { if (!$token = $response->headers->get('X-Debug-Token')) { - return false; + return null; } return $this->loadProfile($token); @@ -81,7 +81,7 @@ class Profiler * * @param string $token A token * - * @return Profile A Profile instance + * @return Profile|null A Profile instance */ public function loadProfile($token) { diff --git a/src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php b/src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php index a9ad235c3a..6803579c61 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php @@ -49,6 +49,9 @@ class BundleTest extends TestCase $this->assertNull($bundle2->registerCommands($app)); } + /** + * @group legacy + */ public function testGetContainerExtensionWithInvalidClass() { $this->expectException('LogicException'); diff --git a/src/Symfony/Component/HttpKernel/Tests/DataCollector/LoggerDataCollectorTest.php b/src/Symfony/Component/HttpKernel/Tests/DataCollector/LoggerDataCollectorTest.php index ace4628e09..8b7fbe2a19 100644 --- a/src/Symfony/Component/HttpKernel/Tests/DataCollector/LoggerDataCollectorTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/DataCollector/LoggerDataCollectorTest.php @@ -23,7 +23,7 @@ class LoggerDataCollectorTest extends TestCase ->getMockBuilder('Symfony\Component\HttpKernel\Log\DebugLoggerInterface') ->setMethods(['countErrors', 'getLogs', 'clear']) ->getMock(); - $logger->expects($this->once())->method('countErrors')->willReturn('foo'); + $logger->expects($this->once())->method('countErrors')->willReturn(123); $logger->expects($this->exactly(2))->method('getLogs')->willReturn([]); $c = new LoggerDataCollector($logger, __DIR__.'/'); diff --git a/src/Symfony/Component/HttpKernel/Tests/DataCollector/TimeDataCollectorTest.php b/src/Symfony/Component/HttpKernel/Tests/DataCollector/TimeDataCollectorTest.php index e044e5e1ad..9de9eb599a 100644 --- a/src/Symfony/Component/HttpKernel/Tests/DataCollector/TimeDataCollectorTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/DataCollector/TimeDataCollectorTest.php @@ -44,7 +44,7 @@ class TimeDataCollectorTest extends TestCase $this->assertEquals(0, $c->getStartTime()); $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock(); - $kernel->expects($this->once())->method('getStartTime')->willReturn(123456); + $kernel->expects($this->once())->method('getStartTime')->willReturn(123456.0); $c = new TimeDataCollector($kernel); $request = new Request(); diff --git a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php index 9a19cd3ffe..10acb00a96 100644 --- a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php @@ -721,8 +721,8 @@ EOF; { $this->expectException('LogicException'); $this->expectExceptionMessage('Trying to register two bundles with the same name "DuplicateName"'); - $fooBundle = $this->getBundle(null, null, 'FooBundle', 'DuplicateName'); - $barBundle = $this->getBundle(null, null, 'BarBundle', 'DuplicateName'); + $fooBundle = $this->getBundle(__DIR__.'/Fixtures/FooBundle', null, 'FooBundle', 'DuplicateName'); + $barBundle = $this->getBundle(__DIR__.'/Fixtures/BarBundle', null, 'BarBundle', 'DuplicateName'); $kernel = $this->getKernel([], [$fooBundle, $barBundle]); $kernel->boot();