[HttpKernel] Fix return type declarations

This commit is contained in:
Nicolas Grekas 2019-08-23 13:30:52 +02:00
parent e0d79f71ed
commit 05fe553666
19 changed files with 42 additions and 39 deletions

View File

@ -24,16 +24,16 @@ class ProfilerTest extends AbstractWebTestCase
} }
$client->request('GET', '/profiler'); $client->request('GET', '/profiler');
$this->assertFalse($client->getProfile()); $this->assertNull($client->getProfile());
// enable the profiler for the next request // enable the profiler for the next request
$client->enableProfiler(); $client->enableProfiler();
$this->assertFalse($client->getProfile()); $this->assertNull($client->getProfile());
$client->request('GET', '/profiler'); $client->request('GET', '/profiler');
$this->assertIsObject($client->getProfile()); $this->assertIsObject($client->getProfile());
$client->request('GET', '/profiler'); $client->request('GET', '/profiler');
$this->assertFalse($client->getProfile()); $this->assertNull($client->getProfile());
} }
public function getConfigs() public function getConfigs()

View File

@ -107,7 +107,7 @@ class Request
/** /**
* Gets the request raw body data. * Gets the request raw body data.
* *
* @return string The request raw body data * @return string|null The request raw body data
*/ */
public function getContent() public function getContent()
{ {

View File

@ -444,8 +444,6 @@ class Container implements ResettableContainerInterface
/** /**
* Creates a service by requiring its factory file. * Creates a service by requiring its factory file.
*
* @return object The service created by the file
*/ */
protected function load($file) protected function load($file)
{ {

View File

@ -21,9 +21,7 @@ interface DumperInterface
/** /**
* Dumps the service container. * Dumps the service container.
* *
* @param array $options An array of options * @return string|array The representation of the service container
*
* @return string The representation of the service container
*/ */
public function dump(array $options = []); public function dump(array $options = []);
} }

View File

@ -85,10 +85,10 @@ class ControllerResolver implements ArgumentResolverInterface, ControllerResolve
} }
} }
try {
$callable = $this->createController($controller); $callable = $this->createController($controller);
} catch (\InvalidArgumentException $e) {
if (!\is_callable($callable)) { throw new \InvalidArgumentException(sprintf('The controller for URI "%s" is not callable. %s', $request->getPathInfo(), $e->getMessage()));
throw new \InvalidArgumentException(sprintf('The controller for URI "%s" is not callable. %s', $request->getPathInfo(), $this->getControllerError($callable)));
} }
return $callable; return $callable;
@ -165,7 +165,7 @@ class ControllerResolver implements ArgumentResolverInterface, ControllerResolve
* *
* @return callable A PHP callable * @return callable A PHP callable
* *
* @throws \InvalidArgumentException * @throws \InvalidArgumentException When the controller cannot be created
*/ */
protected function createController($controller) protected function createController($controller)
{ {
@ -179,7 +179,13 @@ class ControllerResolver implements ArgumentResolverInterface, ControllerResolve
throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class)); 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;
} }
/** /**

View File

@ -119,7 +119,7 @@ class ConfigDataCollector extends DataCollector implements LateDataCollectorInte
/** /**
* Gets the token. * Gets the token.
* *
* @return string The token * @return string|null The token
*/ */
public function getToken() public function getToken()
{ {

View File

@ -55,7 +55,7 @@ class ExceptionDataCollector extends DataCollector
/** /**
* Gets the exception. * Gets the exception.
* *
* @return \Exception The exception * @return \Exception|FlattenException
*/ */
public function getException() public function getException()
{ {

View File

@ -72,11 +72,6 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
} }
} }
/**
* Gets the logs.
*
* @return array An array of logs
*/
public function getLogs() public function getLogs()
{ {
return isset($this->data['logs']) ? $this->data['logs'] : []; return isset($this->data['logs']) ? $this->data['logs'] : [];

View File

@ -132,7 +132,7 @@ class TimeDataCollector extends DataCollector implements LateDataCollectorInterf
/** /**
* Gets the request time. * Gets the request time.
* *
* @return int The time * @return float
*/ */
public function getStartTime() public function getStartTime()
{ {

View File

@ -110,7 +110,7 @@ abstract class AbstractSurrogate implements SurrogateInterface
} }
} }
return null; return '';
} }
/** /**

View File

@ -95,6 +95,6 @@ class Ssi extends AbstractSurrogate
// remove SSI/1.0 from the Surrogate-Control header // remove SSI/1.0 from the Surrogate-Control header
$this->removeFromControl($response); $this->removeFromControl($response);
return null; return $response;
} }
} }

View File

@ -206,7 +206,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
/** /**
* Gets a HTTP kernel from the container. * Gets a HTTP kernel from the container.
* *
* @return HttpKernel * @return HttpKernelInterface
*/ */
protected function getHttpKernel() protected function getHttpKernel()
{ {
@ -425,7 +425,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
*/ */
public function getStartTime() public function getStartTime()
{ {
return $this->debug ? $this->startTime : -INF; return $this->debug && null !== $this->startTime ? $this->startTime : -INF;
} }
/** /**

View File

@ -138,7 +138,7 @@ interface KernelInterface extends HttpKernelInterface, \Serializable
/** /**
* Gets the request start time (not available if debug is disabled). * 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(); public function getStartTime();

View File

@ -102,7 +102,7 @@ class Profile
/** /**
* Returns the IP. * Returns the IP.
* *
* @return string The IP * @return string|null The IP
*/ */
public function getIp() public function getIp()
{ {
@ -122,7 +122,7 @@ class Profile
/** /**
* Returns the request method. * Returns the request method.
* *
* @return string The request method * @return string|null The request method
*/ */
public function getMethod() public function getMethod()
{ {
@ -137,13 +137,16 @@ class Profile
/** /**
* Returns the URL. * Returns the URL.
* *
* @return string The URL * @return string|null The URL
*/ */
public function getUrl() public function getUrl()
{ {
return $this->url; return $this->url;
} }
/**
* @param string $url
*/
public function setUrl($url) public function setUrl($url)
{ {
$this->url = $url; $this->url = $url;
@ -180,7 +183,7 @@ class Profile
} }
/** /**
* @return int * @return int|null
*/ */
public function getStatusCode() public function getStatusCode()
{ {

View File

@ -65,12 +65,12 @@ class Profiler
/** /**
* Loads the Profile for the given Response. * Loads the Profile for the given Response.
* *
* @return Profile|false A Profile instance * @return Profile|null A Profile instance
*/ */
public function loadProfileFromResponse(Response $response) public function loadProfileFromResponse(Response $response)
{ {
if (!$token = $response->headers->get('X-Debug-Token')) { if (!$token = $response->headers->get('X-Debug-Token')) {
return false; return null;
} }
return $this->loadProfile($token); return $this->loadProfile($token);
@ -81,7 +81,7 @@ class Profiler
* *
* @param string $token A token * @param string $token A token
* *
* @return Profile A Profile instance * @return Profile|null A Profile instance
*/ */
public function loadProfile($token) public function loadProfile($token)
{ {

View File

@ -49,6 +49,9 @@ class BundleTest extends TestCase
$this->assertNull($bundle2->registerCommands($app)); $this->assertNull($bundle2->registerCommands($app));
} }
/**
* @group legacy
*/
public function testGetContainerExtensionWithInvalidClass() public function testGetContainerExtensionWithInvalidClass()
{ {
$this->expectException('LogicException'); $this->expectException('LogicException');

View File

@ -23,7 +23,7 @@ class LoggerDataCollectorTest extends TestCase
->getMockBuilder('Symfony\Component\HttpKernel\Log\DebugLoggerInterface') ->getMockBuilder('Symfony\Component\HttpKernel\Log\DebugLoggerInterface')
->setMethods(['countErrors', 'getLogs', 'clear']) ->setMethods(['countErrors', 'getLogs', 'clear'])
->getMock(); ->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([]); $logger->expects($this->exactly(2))->method('getLogs')->willReturn([]);
$c = new LoggerDataCollector($logger, __DIR__.'/'); $c = new LoggerDataCollector($logger, __DIR__.'/');

View File

@ -44,7 +44,7 @@ class TimeDataCollectorTest extends TestCase
$this->assertEquals(0, $c->getStartTime()); $this->assertEquals(0, $c->getStartTime());
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock(); $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); $c = new TimeDataCollector($kernel);
$request = new Request(); $request = new Request();

View File

@ -721,8 +721,8 @@ EOF;
{ {
$this->expectException('LogicException'); $this->expectException('LogicException');
$this->expectExceptionMessage('Trying to register two bundles with the same name "DuplicateName"'); $this->expectExceptionMessage('Trying to register two bundles with the same name "DuplicateName"');
$fooBundle = $this->getBundle(null, null, 'FooBundle', 'DuplicateName'); $fooBundle = $this->getBundle(__DIR__.'/Fixtures/FooBundle', null, 'FooBundle', 'DuplicateName');
$barBundle = $this->getBundle(null, null, 'BarBundle', 'DuplicateName'); $barBundle = $this->getBundle(__DIR__.'/Fixtures/BarBundle', null, 'BarBundle', 'DuplicateName');
$kernel = $this->getKernel([], [$fooBundle, $barBundle]); $kernel = $this->getKernel([], [$fooBundle, $barBundle]);
$kernel->boot(); $kernel->boot();