[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');
$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()

View File

@ -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()
{

View File

@ -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)
{

View File

@ -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 = []);
}

View File

@ -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;
}
/**

View File

@ -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()
{

View File

@ -55,7 +55,7 @@ class ExceptionDataCollector extends DataCollector
/**
* Gets the exception.
*
* @return \Exception The exception
* @return \Exception|FlattenException
*/
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()
{
return isset($this->data['logs']) ? $this->data['logs'] : [];

View File

@ -132,7 +132,7 @@ class TimeDataCollector extends DataCollector implements LateDataCollectorInterf
/**
* Gets the request time.
*
* @return int The time
* @return float
*/
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
$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.
*
* @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;
}
/**

View File

@ -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();

View File

@ -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()
{

View File

@ -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)
{

View File

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

View File

@ -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__.'/');

View File

@ -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();

View File

@ -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();