From dbcc6cbb8f9da67415fd6e13242e426ccc7e6c27 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Fri, 16 Aug 2019 01:42:44 +0200 Subject: [PATCH] [HttpKernel] Add more parameter types. --- .../Component/HttpKernel/CacheClearer/Psr6CacheClearer.php | 6 +++--- .../Component/HttpKernel/CacheWarmer/CacheWarmer.php | 2 +- .../Component/HttpKernel/Debug/FileLinkFormatter.php | 2 +- .../HttpKernel/EventListener/ExceptionListener.php | 2 +- src/Symfony/Component/HttpKernel/HttpCache/Store.php | 2 +- .../Component/HttpKernel/HttpCache/SubRequestHandler.php | 2 +- .../Component/HttpKernel/Profiler/FileProfilerStorage.php | 4 ++-- src/Symfony/Component/HttpKernel/Profiler/Profile.php | 2 +- .../HttpKernel/Tests/CacheWarmer/CacheWarmerTest.php | 4 ++-- src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php | 3 ++- src/Symfony/Component/HttpKernel/Tests/KernelTest.php | 4 ++-- .../HttpKernel/Tests/Profiler/FileProfilerStorageTest.php | 7 +++++++ 12 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/CacheClearer/Psr6CacheClearer.php b/src/Symfony/Component/HttpKernel/CacheClearer/Psr6CacheClearer.php index 1b9f8d5e29fb8..ab37853d3121a 100644 --- a/src/Symfony/Component/HttpKernel/CacheClearer/Psr6CacheClearer.php +++ b/src/Symfony/Component/HttpKernel/CacheClearer/Psr6CacheClearer.php @@ -23,12 +23,12 @@ public function __construct(array $pools = []) $this->pools = $pools; } - public function hasPool($name) + public function hasPool(string $name) { return isset($this->pools[$name]); } - public function getPool($name) + public function getPool(string $name) { if (!$this->hasPool($name)) { throw new \InvalidArgumentException(sprintf('Cache pool not found: %s.', $name)); @@ -37,7 +37,7 @@ public function getPool($name) return $this->pools[$name]; } - public function clearPool($name) + public function clearPool(string $name) { if (!isset($this->pools[$name])) { throw new \InvalidArgumentException(sprintf('Cache pool not found: %s.', $name)); diff --git a/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmer.php b/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmer.php index 52dc2ad2c3d83..aef42d62f4265 100644 --- a/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmer.php +++ b/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmer.php @@ -18,7 +18,7 @@ */ abstract class CacheWarmer implements CacheWarmerInterface { - protected function writeCacheFile($file, $content) + protected function writeCacheFile(string $file, $content) { $tmpFile = @tempnam(\dirname($file), basename($file)); if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $file)) { diff --git a/src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php b/src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php index e6d31516d7832..d8d7aed5d4387 100644 --- a/src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php +++ b/src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php @@ -76,7 +76,7 @@ public function __sleep(): array /** * @internal */ - public static function generateUrlFormat(UrlGeneratorInterface $router, $routeName, $queryString): ?string + public static function generateUrlFormat(UrlGeneratorInterface $router, string $routeName, string $queryString): ?string { try { return $router->generate($routeName).$queryString; diff --git a/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php b/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php index 73b3044ff6348..1e9aadac52e2a 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php @@ -33,7 +33,7 @@ class ExceptionListener implements EventSubscriberInterface protected $logger; protected $debug; - public function __construct($controller, LoggerInterface $logger = null, $debug = false) + public function __construct($controller, LoggerInterface $logger = null, bool $debug = false) { $this->controller = $controller; $this->logger = $logger; diff --git a/src/Symfony/Component/HttpKernel/HttpCache/Store.php b/src/Symfony/Component/HttpKernel/HttpCache/Store.php index 3aa4fcf6dc8b6..b7953e1303d1a 100644 --- a/src/Symfony/Component/HttpKernel/HttpCache/Store.php +++ b/src/Symfony/Component/HttpKernel/HttpCache/Store.php @@ -390,7 +390,7 @@ private function save(string $key, string $data): bool return true; } - public function getPath($key) + public function getPath(string $key) { return $this->root.\DIRECTORY_SEPARATOR.substr($key, 0, 2).\DIRECTORY_SEPARATOR.substr($key, 2, 2).\DIRECTORY_SEPARATOR.substr($key, 4, 2).\DIRECTORY_SEPARATOR.substr($key, 6); } diff --git a/src/Symfony/Component/HttpKernel/HttpCache/SubRequestHandler.php b/src/Symfony/Component/HttpKernel/HttpCache/SubRequestHandler.php index cef9817e01d6c..294b964acc670 100644 --- a/src/Symfony/Component/HttpKernel/HttpCache/SubRequestHandler.php +++ b/src/Symfony/Component/HttpKernel/HttpCache/SubRequestHandler.php @@ -23,7 +23,7 @@ */ class SubRequestHandler { - public static function handle(HttpKernelInterface $kernel, Request $request, $type, $catch): Response + public static function handle(HttpKernelInterface $kernel, Request $request, int $type, bool $catch): Response { // save global state related to trusted headers and proxies $trustedProxies = Request::getTrustedProxies(); diff --git a/src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php b/src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php index 7d8d9502ec94d..4db3ae3b6e555 100644 --- a/src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php +++ b/src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php @@ -113,7 +113,7 @@ public function purge() /** * {@inheritdoc} */ - public function read($token) + public function read(string $token) { if (!$token || !file_exists($file = $this->getFilename($token))) { return null; @@ -257,7 +257,7 @@ protected function readLineFromFile($file) return '' === $line ? null : $line; } - protected function createProfileFromData($token, $data, $parent = null) + protected function createProfileFromData(string $token, array $data, Profile $parent = null) { $profile = new Profile($token); $profile->setIp($data['ip']); diff --git a/src/Symfony/Component/HttpKernel/Profiler/Profile.php b/src/Symfony/Component/HttpKernel/Profiler/Profile.php index d082dd35906c1..680e1229d080e 100644 --- a/src/Symfony/Component/HttpKernel/Profiler/Profile.php +++ b/src/Symfony/Component/HttpKernel/Profiler/Profile.php @@ -114,7 +114,7 @@ public function getMethod() return $this->method; } - public function setMethod($method) + public function setMethod(string $method) { $this->method = $method; } diff --git a/src/Symfony/Component/HttpKernel/Tests/CacheWarmer/CacheWarmerTest.php b/src/Symfony/Component/HttpKernel/Tests/CacheWarmer/CacheWarmerTest.php index b5acb12618493..f3c5ff921ca24 100644 --- a/src/Symfony/Component/HttpKernel/Tests/CacheWarmer/CacheWarmerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/CacheWarmer/CacheWarmerTest.php @@ -49,12 +49,12 @@ class TestCacheWarmer extends CacheWarmer { protected $file; - public function __construct($file) + public function __construct(string $file) { $this->file = $file; } - public function warmUp($cacheDir) + public function warmUp(string $cacheDir) { $this->writeCacheFile($this->file, 'content'); } diff --git a/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php b/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php index 9a6170c086d35..2f33cafc3ac22 100644 --- a/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php @@ -20,6 +20,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface; use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; +use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\ControllerDoesNotReturnResponseException; use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; @@ -122,7 +123,7 @@ public function getStatusCodes() public function testHandleWhenAnExceptionIsHandledWithASpecificStatusCode($expectedStatusCode) { $dispatcher = new EventDispatcher(); - $dispatcher->addListener(KernelEvents::EXCEPTION, function ($event) use ($expectedStatusCode) { + $dispatcher->addListener(KernelEvents::EXCEPTION, function (ExceptionEvent $event) use ($expectedStatusCode) { $event->allowCustomResponseCode(); $event->setResponse(new Response('', $expectedStatusCode)); }); diff --git a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php index 59e949713455b..691ec6702348c 100644 --- a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php @@ -641,7 +641,7 @@ protected function getKernel(array $methods = [], array $bundles = []) return $kernel; } - protected function getKernelForTest(array $methods = [], $debug = false) + protected function getKernelForTest(array $methods = [], bool $debug = false) { $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest') ->setConstructorArgs(['test', $debug]) @@ -661,7 +661,7 @@ public function terminate() $this->terminateCalled = true; } - public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true) + public function handle(Request $request, int $type = self::MASTER_REQUEST, bool $catch = true) { } } diff --git a/src/Symfony/Component/HttpKernel/Tests/Profiler/FileProfilerStorageTest.php b/src/Symfony/Component/HttpKernel/Tests/Profiler/FileProfilerStorageTest.php index 16aa973f9eb6e..2bd2a2705b7b3 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Profiler/FileProfilerStorageTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Profiler/FileProfilerStorageTest.php @@ -53,11 +53,13 @@ public function testChildren() $parentProfile->setIp('127.0.0.1'); $parentProfile->setUrl('http://foo.bar/parent'); $parentProfile->setStatusCode(200); + $parentProfile->setMethod('GET'); $childProfile = new Profile('token_child'); $childProfile->setIp('127.0.0.1'); $childProfile->setUrl('http://foo.bar/child'); $childProfile->setStatusCode(200); + $childProfile->setMethod('GET'); $parentProfile->addChild($childProfile); @@ -86,6 +88,7 @@ public function testStoreSpecialCharsInUrl() $profile->setUrl('http://foo.bar/\''); $profile->setIp('127.0.0.1'); $profile->setStatusCode(200); + $profile->setMethod('GET'); $this->storage->write($profile); $this->assertNotFalse($this->storage->read('simple_quote'), '->write() accepts single quotes in URL'); @@ -94,6 +97,7 @@ public function testStoreSpecialCharsInUrl() $profile->setUrl('http://foo.bar/"'); $profile->setIp('127.0.0.1'); $profile->setStatusCode(200); + $profile->setMethod('GET'); $this->storage->write($profile); $this->assertNotFalse($this->storage->read('double_quote'), '->write() accepts double quotes in URL'); @@ -102,6 +106,7 @@ public function testStoreSpecialCharsInUrl() $profile->setUrl('http://foo.bar/\\'); $profile->setIp('127.0.0.1'); $profile->setStatusCode(200); + $profile->setMethod('GET'); $this->storage->write($profile); $this->assertNotFalse($this->storage->read('backslash'), '->write() accepts backslash in URL'); @@ -110,6 +115,7 @@ public function testStoreSpecialCharsInUrl() $profile->setUrl('http://foo.bar/,'); $profile->setIp('127.0.0.1'); $profile->setStatusCode(200); + $profile->setMethod('GET'); $this->storage->write($profile); $this->assertNotFalse($this->storage->read('comma'), '->write() accepts comma in URL'); @@ -121,6 +127,7 @@ public function testStoreDuplicateToken() $profile->setUrl('http://example.com/'); $profile->setIp('127.0.0.1'); $profile->setStatusCode(200); + $profile->setMethod('GET'); $this->assertTrue($this->storage->write($profile), '->write() returns true when the token is unique');