From f7abdecd641b7c721b7a52c56874c8838c54c91b Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 16 Jul 2021 11:34:48 +0200 Subject: [PATCH] More return type fixes --- .github/patch-types.php | 1 + .../Tests/DependencyInjection/SecurityExtensionTest.php | 4 ++++ src/Symfony/Component/Cache/Tests/Fixtures/ArrayCache.php | 3 +++ .../DependencyInjection/Loader/YamlFileLoader.php | 5 +---- .../Tests/Fixtures/includes/ProjectWithXsdExtension.php | 2 +- .../Session/Storage/Handler/MongoDbSessionHandler.php | 2 ++ .../Session/Storage/Handler/RedisSessionHandler.php | 1 + src/Symfony/Component/HttpKernel/Tests/KernelTest.php | 7 +++++-- src/Symfony/Component/Ldap/Adapter/ExtLdap/Collection.php | 5 +++++ .../Tests/Security/CheckLdapCredentialsListenerTest.php | 4 ++++ src/Symfony/Component/Lock/Tests/LockTest.php | 4 ++-- .../Security/Http/Tests/Firewall/AccessListenerTest.php | 3 +++ .../Tests/Normalizer/AbstractObjectNormalizerTest.php | 3 +++ .../Serializer/Tests/Normalizer/ObjectNormalizerTest.php | 4 +++- .../Serializer/Tests/Normalizer/TestNormalizer.php | 1 + 15 files changed, 39 insertions(+), 10 deletions(-) diff --git a/.github/patch-types.php b/.github/patch-types.php index 33ba6347a3ef0..d5897449138cd 100644 --- a/.github/patch-types.php +++ b/.github/patch-types.php @@ -15,6 +15,7 @@ switch (true) { case false !== strpos($file = realpath($file), '/vendor/'): case false !== strpos($file, '/src/Symfony/Bridge/PhpUnit/'): + case false !== strpos($file, '/Attribute/'): case false !== strpos($file, '/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Validation/Article.php'): case false !== strpos($file, '/src/Symfony/Component/Cache/Tests/Fixtures/DriverWrapper.php'): case false !== strpos($file, '/src/Symfony/Component/Config/Tests/Fixtures/BadFileName.php'): diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php index 5d0c55da94b21..f0c2af100e2ac 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php @@ -856,6 +856,10 @@ public function onAuthenticationSuccess(Request $request, TokenInterface $token, public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response { } + + public function createToken(Passport $passport, string $firewallName): TokenInterface + { + } } class NullAuthenticator implements GuardAuthenticatorInterface diff --git a/src/Symfony/Component/Cache/Tests/Fixtures/ArrayCache.php b/src/Symfony/Component/Cache/Tests/Fixtures/ArrayCache.php index 724e605e58d39..b803592d85d74 100644 --- a/src/Symfony/Component/Cache/Tests/Fixtures/ArrayCache.php +++ b/src/Symfony/Component/Cache/Tests/Fixtures/ArrayCache.php @@ -8,6 +8,9 @@ class ArrayCache extends CacheProvider { private $data = []; + /** + * @return mixed + */ protected function doFetch($id) { return $this->doContains($id) ? $this->data[$id][0] : false; diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index 13ba1ed900b46..85c884f354fe4 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -13,7 +13,6 @@ use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\Argument\AbstractArgument; -use Symfony\Component\DependencyInjection\Argument\ArgumentInterface; use Symfony\Component\DependencyInjection\Argument\BoundArgument; use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; @@ -803,9 +802,7 @@ private function validate($content, string $file): ?array } /** - * Resolves services. - * - * @return array|string|Reference|ArgumentInterface + * @return mixed */ private function resolveServices($value, string $file, bool $isParameter = false) { diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/ProjectWithXsdExtension.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/ProjectWithXsdExtension.php index f986cccec962e..f457abd2a379d 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/ProjectWithXsdExtension.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/ProjectWithXsdExtension.php @@ -2,7 +2,7 @@ class ProjectWithXsdExtension extends ProjectExtension { - public function getXsdValidationBasePath() + public function getXsdValidationBasePath(): string { return __DIR__.'/schema'; } diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php index a422c82c9a17c..f208b3620437d 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/MongoDbSessionHandler.php @@ -82,6 +82,7 @@ public function __construct(\MongoDB\Client $mongo, array $options) /** * @return bool */ + #[\ReturnTypeWillChange] public function close() { return true; @@ -135,6 +136,7 @@ protected function doWrite(string $sessionId, string $data) /** * @return bool */ + #[\ReturnTypeWillChange] public function updateTimestamp($sessionId, $data) { $expiry = new \MongoDB\BSON\UTCDateTime((time() + (int) ini_get('session.gc_maxlifetime')) * 1000); diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php index 1a660574314bd..5cc2e345d8ca8 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/RedisSessionHandler.php @@ -128,6 +128,7 @@ public function gc($maxlifetime) /** * @return bool */ + #[\ReturnTypeWillChange] public function updateTimestamp($sessionId, $data) { return (bool) $this->redis->expire($this->prefix.$sessionId, (int) ($this->ttl ?? ini_get('session.gc_maxlifetime'))); diff --git a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php index 0d71033752fba..6bcad824fedb2 100644 --- a/src/Symfony/Component/HttpKernel/Tests/KernelTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/KernelTest.php @@ -516,17 +516,20 @@ public function load(array $configs, ContainerBuilder $container) $container->setParameter('test.extension-registered', true); } - public function getNamespace() + public function getNamespace(): string { return ''; } + /** + * @return false + */ public function getXsdValidationBasePath() { return false; } - public function getAlias() + public function getAlias(): string { return 'test-extension'; } diff --git a/src/Symfony/Component/Ldap/Adapter/ExtLdap/Collection.php b/src/Symfony/Component/Ldap/Adapter/ExtLdap/Collection.php index d8da8ddbf6586..8724a60d4aa60 100644 --- a/src/Symfony/Component/Ldap/Adapter/ExtLdap/Collection.php +++ b/src/Symfony/Component/Ldap/Adapter/ExtLdap/Collection.php @@ -65,6 +65,7 @@ public function count() /** * @return \Traversable */ + #[\ReturnTypeWillChange] public function getIterator() { if (0 === $this->count()) { @@ -91,6 +92,7 @@ public function getIterator() /** * @return bool */ + #[\ReturnTypeWillChange] public function offsetExists($offset) { $this->toArray(); @@ -101,6 +103,7 @@ public function offsetExists($offset) /** * @return mixed */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { $this->toArray(); @@ -111,6 +114,7 @@ public function offsetGet($offset) /** * @return void */ + #[\ReturnTypeWillChange] public function offsetSet($offset, $value) { $this->toArray(); @@ -121,6 +125,7 @@ public function offsetSet($offset, $value) /** * @return void */ + #[\ReturnTypeWillChange] public function offsetUnset($offset) { $this->toArray(); diff --git a/src/Symfony/Component/Ldap/Tests/Security/CheckLdapCredentialsListenerTest.php b/src/Symfony/Component/Ldap/Tests/Security/CheckLdapCredentialsListenerTest.php index 9a879c22490ef..23e4182b47a33 100644 --- a/src/Symfony/Component/Ldap/Tests/Security/CheckLdapCredentialsListenerTest.php +++ b/src/Symfony/Component/Ldap/Tests/Security/CheckLdapCredentialsListenerTest.php @@ -228,5 +228,9 @@ public function onAuthenticationSuccess(Request $request, TokenInterface $token, public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response { } + + public function createToken(Passport $passport, string $firewallName): TokenInterface + { + } } } diff --git a/src/Symfony/Component/Lock/Tests/LockTest.php b/src/Symfony/Component/Lock/Tests/LockTest.php index 37fcf246e49ef..565ef529a46ed 100644 --- a/src/Symfony/Component/Lock/Tests/LockTest.php +++ b/src/Symfony/Component/Lock/Tests/LockTest.php @@ -456,7 +456,7 @@ public function delete(Key $key) unset($this->keys[spl_object_hash($key)]); } - public function exists(Key $key) + public function exists(Key $key): bool { return isset($this->keys[spl_object_hash($key)]); } @@ -502,7 +502,7 @@ public function delete(Key $key) unset($this->keys[spl_object_hash($key)]); } - public function exists(Key $key) + public function exists(Key $key): bool { return isset($this->keys[spl_object_hash($key)]); } diff --git a/src/Symfony/Component/Security/Http/Tests/Firewall/AccessListenerTest.php b/src/Symfony/Component/Security/Http/Tests/Firewall/AccessListenerTest.php index 8800bf2ba5a74..ab3bdae3ecff0 100644 --- a/src/Symfony/Component/Security/Http/Tests/Firewall/AccessListenerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/Firewall/AccessListenerTest.php @@ -52,6 +52,9 @@ public function isAuthenticated(): bool return true; } + /** + * @return mixed + */ public function getCredentials() { } diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php index 1230aa6536129..e8243b1609ff6 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php @@ -619,6 +619,9 @@ public function setSerializer(SerializerInterface $serializer) class NotSerializable { + /** + * @return array + */ public function __sleep() { if (class_exists(\Error::class)) { diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php index 860c16f6036a4..84ac7418c5307 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php @@ -601,9 +601,11 @@ public function testNormalizeNotSerializableContext() public function testDefaultExcludeFromCacheKey() { $normalizer = new class(null, null, null, null, null, null, [ObjectNormalizer::EXCLUDE_FROM_CACHE_KEY => ['foo']]) extends ObjectNormalizer { - protected function isCircularReference($object, &$context) + protected function isCircularReference($object, &$context): bool { ObjectNormalizerTest::assertContains('foo', $this->defaultContext[ObjectNormalizer::EXCLUDE_FROM_CACHE_KEY]); + + return false; } }; $normalizer->normalize(new ObjectDummy()); diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/TestNormalizer.php b/src/Symfony/Component/Serializer/Tests/Normalizer/TestNormalizer.php index 86835a6086e95..75a999485bec6 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/TestNormalizer.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/TestNormalizer.php @@ -25,6 +25,7 @@ class TestNormalizer implements NormalizerInterface */ public function normalize($object, string $format = null, array $context = []) { + return null; } /**