From 1ea501dfb2d477b5b136d171a8965055cfd989ef Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 12 Aug 2021 16:31:53 +0200 Subject: [PATCH] Add return types to bridges --- .../Doctrine/CacheWarmer/ProxyCacheWarmer.php | 6 ++--- .../Doctrine/ContainerAwareEventManager.php | 18 ++++--------- .../DataCollector/DoctrineDataCollector.php | 4 +-- .../AbstractDoctrineExtension.php | 26 ++++++------------- .../CompilerPass/RegisterMappingsPass.php | 6 ++--- .../Form/ChoiceList/EntityLoaderInterface.php | 4 +-- .../Form/ChoiceList/ORMQueryBuilderLoader.php | 4 +-- .../CollectionToArrayTransformer.php | 4 +-- .../Doctrine/Form/DoctrineOrmExtension.php | 5 ++-- .../Doctrine/Form/DoctrineOrmTypeGuesser.php | 8 +++--- .../MergeDoctrineCollectionListener.php | 2 +- .../Doctrine/Form/Type/DoctrineType.php | 9 ++----- .../Bridge/Doctrine/Form/Type/EntityType.php | 6 ++--- .../Bridge/Doctrine/Logger/DbalLogger.php | 8 ++---- .../Bridge/Doctrine/ManagerRegistry.php | 8 ++---- ...rineClearEntityManagerWorkerSubscriber.php | 2 +- .../PropertyInfo/DoctrineExtractor.php | 8 +++--- .../RememberMe/DoctrineTokenProvider.php | 2 +- .../Security/User/EntityUserProvider.php | 6 ++--- .../Security/User/UserLoaderInterface.php | 4 +-- .../Doctrine/Test/DoctrineTestHelper.php | 14 +++------- .../Doctrine/Test/TestRepositoryFactory.php | 4 +-- .../Validator/Constraints/UniqueEntity.php | 10 +++---- .../Monolog/Command/ServerLogCommand.php | 4 +-- .../Monolog/Formatter/ConsoleFormatter.php | 8 ++---- .../Monolog/Formatter/VarDumperFormatter.php | 8 ++---- .../Bridge/Monolog/Handler/ConsoleHandler.php | 2 +- .../Handler/ElasticsearchLogstashHandler.php | 5 +--- src/Symfony/Bridge/Monolog/Logger.php | 4 +-- .../Processor/ConsoleCommandProcessor.php | 2 +- .../Monolog/Processor/DebugProcessor.php | 4 +-- .../Instantiator/RuntimeInstantiator.php | 2 +- src/Symfony/Bridge/Twig/AppVariable.php | 14 +++++----- .../Bridge/Twig/Command/DebugCommand.php | 2 +- .../Bridge/Twig/Command/LintCommand.php | 2 +- .../Bridge/Twig/Form/TwigRendererEngine.php | 4 +-- .../Bridge/Twig/Mime/NotificationEmail.php | 12 ++++----- .../Bridge/Twig/Mime/TemplatedEmail.php | 6 ++--- src/Symfony/Bridge/Twig/NodeVisitor/Scope.php | 10 +++---- .../Bridge/Twig/Translation/TwigExtractor.php | 4 +-- .../Bridge/Twig/UndefinedCallableHandler.php | 4 +-- 41 files changed, 103 insertions(+), 162 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php b/src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php index bbee8cea3f3f8..e90c82af15b4a 100644 --- a/src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php +++ b/src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php @@ -33,10 +33,8 @@ public function __construct(ManagerRegistry $registry) /** * This cache warmer is not optional, without proxies fatal error occurs! - * - * @return bool */ - public function isOptional() + public function isOptional(): bool { return false; } @@ -46,7 +44,7 @@ public function isOptional() * * @return string[] A list of files to preload on PHP 7.4+ */ - public function warmUp(string $cacheDir) + public function warmUp(string $cacheDir): array { $files = []; foreach ($this->registry->getManagers() as $em) { diff --git a/src/Symfony/Bridge/Doctrine/ContainerAwareEventManager.php b/src/Symfony/Bridge/Doctrine/ContainerAwareEventManager.php index c3f3cb1431fbb..ebd01f1eae644 100644 --- a/src/Symfony/Bridge/Doctrine/ContainerAwareEventManager.php +++ b/src/Symfony/Bridge/Doctrine/ContainerAwareEventManager.php @@ -46,10 +46,8 @@ public function __construct(ContainerInterface $container, array $subscriberIds /** * {@inheritdoc} - * - * @return void */ - public function dispatchEvent($eventName, EventArgs $eventArgs = null) + public function dispatchEvent($eventName, EventArgs $eventArgs = null): void { if (!$this->initializedSubscribers) { $this->initializeSubscribers(); @@ -74,7 +72,7 @@ public function dispatchEvent($eventName, EventArgs $eventArgs = null) * * @return object[][] */ - public function getListeners($event = null) + public function getListeners($event = null): array { if (!$this->initializedSubscribers) { $this->initializeSubscribers(); @@ -98,10 +96,8 @@ public function getListeners($event = null) /** * {@inheritdoc} - * - * @return bool */ - public function hasListeners($event) + public function hasListeners($event): bool { if (!$this->initializedSubscribers) { $this->initializeSubscribers(); @@ -112,10 +108,8 @@ public function hasListeners($event) /** * {@inheritdoc} - * - * @return void */ - public function addEventListener($events, $listener) + public function addEventListener($events, $listener): void { if (!$this->initializedSubscribers) { $this->initializeSubscribers(); @@ -138,10 +132,8 @@ public function addEventListener($events, $listener) /** * {@inheritdoc} - * - * @return void */ - public function removeEventListener($events, $listener) + public function removeEventListener($events, $listener): void { if (!$this->initializedSubscribers) { $this->initializeSubscribers(); diff --git a/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php b/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php index 2e8d2c709405f..d932b71c8c88f 100644 --- a/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php +++ b/src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php @@ -114,7 +114,7 @@ public function getTime() /** * {@inheritdoc} */ - public function getName() + public function getName(): string { return 'db'; } @@ -122,7 +122,7 @@ public function getName() /** * {@inheritdoc} */ - protected function getCasters() + protected function getCasters(): array { return parent::getCasters() + [ ObjectParameter::class => static function (ObjectParameter $o, array $a, Stub $s): array { diff --git a/src/Symfony/Bridge/Doctrine/DependencyInjection/AbstractDoctrineExtension.php b/src/Symfony/Bridge/Doctrine/DependencyInjection/AbstractDoctrineExtension.php index 868042bc31e6f..f542c8479fbfb 100644 --- a/src/Symfony/Bridge/Doctrine/DependencyInjection/AbstractDoctrineExtension.php +++ b/src/Symfony/Bridge/Doctrine/DependencyInjection/AbstractDoctrineExtension.php @@ -152,7 +152,7 @@ protected function setMappingDriverConfig(array $mappingConfig, string $mappingN * * @return array|false */ - protected function getMappingDriverBundleConfigDefaults(array $bundleConfig, \ReflectionClass $bundle, ContainerBuilder $container) + protected function getMappingDriverBundleConfigDefaults(array $bundleConfig, \ReflectionClass $bundle, ContainerBuilder $container): array|false { $bundleDir = \dirname($bundle->getFileName()); @@ -261,7 +261,7 @@ protected function assertValidMappingConfiguration(array $mappingConfig, string * * @return string|null A metadata driver short name, if one can be detected */ - protected function detectMetadataDriver(string $dir, ContainerBuilder $container) + protected function detectMetadataDriver(string $dir, ContainerBuilder $container): ?string { $configPath = $this->getMappingResourceConfigDirectory(); $extension = $this->getMappingResourceExtension(); @@ -300,11 +300,9 @@ protected function loadObjectManagerCacheDriver(array $objectManager, ContainerB /** * Loads a cache driver. * - * @return string - * * @throws \InvalidArgumentException */ - protected function loadCacheDriver(string $cacheName, string $objectManagerName, array $cacheDriver, ContainerBuilder $container) + protected function loadCacheDriver(string $cacheName, string $objectManagerName, array $cacheDriver, ContainerBuilder $container): string { $cacheDriverServiceId = $this->getObjectManagerElementName($objectManagerName.'_'.$cacheName); @@ -381,7 +379,7 @@ protected function loadCacheDriver(string $cacheName, string $objectManagerName, * * @return array The modified version of $managerConfigs */ - protected function fixManagersAutoMappings(array $managerConfigs, array $bundles) + protected function fixManagersAutoMappings(array $managerConfigs, array $bundles): array { if ($autoMappedManager = $this->validateAutoMapping($managerConfigs)) { foreach (array_keys($bundles) as $bundle) { @@ -405,33 +403,25 @@ protected function fixManagersAutoMappings(array $managerConfigs, array $bundles * Prefixes the relative dependency injection container path with the object manager prefix. * * @example $name is 'entity_manager' then the result would be 'doctrine.orm.entity_manager' - * - * @return string */ - abstract protected function getObjectManagerElementName(string $name); + abstract protected function getObjectManagerElementName(string $name): string; /** * Noun that describes the mapped objects such as Entity or Document. * * Will be used for autodetection of persistent objects directory. - * - * @return string */ - abstract protected function getMappingObjectDefaultName(); + abstract protected function getMappingObjectDefaultName(): string; /** * Relative path from the bundle root to the directory where mapping files reside. - * - * @return string */ - abstract protected function getMappingResourceConfigDirectory(); + abstract protected function getMappingResourceConfigDirectory(): string; /** * Extension used by the mapping files. - * - * @return string */ - abstract protected function getMappingResourceExtension(); + abstract protected function getMappingResourceExtension(): string; /** * The class name used by the various mapping drivers. diff --git a/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterMappingsPass.php b/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterMappingsPass.php index 6db44df08d256..ed0ef6407b9e3 100644 --- a/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterMappingsPass.php +++ b/src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterMappingsPass.php @@ -170,7 +170,7 @@ public function process(ContainerBuilder $container) * @throws InvalidArgumentException if non of the managerParameters has a * non-empty value */ - protected function getChainDriverServiceName(ContainerBuilder $container) + protected function getChainDriverServiceName(ContainerBuilder $container): string { return sprintf($this->driverPattern, $this->getManagerName($container)); } @@ -183,7 +183,7 @@ protected function getChainDriverServiceName(ContainerBuilder $container) * * @return Definition|Reference the metadata driver to add to all chain drivers */ - protected function getDriver(ContainerBuilder $container) + protected function getDriver(ContainerBuilder $container): Definition|Reference { return $this->driver; } @@ -230,7 +230,7 @@ private function getManagerName(ContainerBuilder $container): string * * @return bool whether this compiler pass really should register the mappings */ - protected function enabled(ContainerBuilder $container) + protected function enabled(ContainerBuilder $container): bool { return !$this->enabledParameter || $container->hasParameter($this->enabledParameter); } diff --git a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityLoaderInterface.php b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityLoaderInterface.php index 8eb5a84484503..39121374ffe74 100644 --- a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityLoaderInterface.php +++ b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityLoaderInterface.php @@ -23,12 +23,12 @@ interface EntityLoaderInterface * * @return array The entities */ - public function getEntities(); + public function getEntities(): array; /** * Returns an array of entities matching the given identifiers. * * @return array The entities */ - public function getEntitiesByIds(string $identifier, array $values); + public function getEntitiesByIds(string $identifier, array $values): array; } diff --git a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php index 876ec88836e6c..b0121df1b1da5 100644 --- a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php +++ b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/ORMQueryBuilderLoader.php @@ -41,7 +41,7 @@ public function __construct(QueryBuilder $queryBuilder) /** * {@inheritdoc} */ - public function getEntities() + public function getEntities(): array { return $this->queryBuilder->getQuery()->execute(); } @@ -49,7 +49,7 @@ public function getEntities() /** * {@inheritdoc} */ - public function getEntitiesByIds(string $identifier, array $values) + public function getEntitiesByIds(string $identifier, array $values): array { if (null !== $this->queryBuilder->getMaxResults() || null !== $this->queryBuilder->getFirstResult()) { // an offset or a limit would apply on results including the where clause with submitted id values diff --git a/src/Symfony/Bridge/Doctrine/Form/DataTransformer/CollectionToArrayTransformer.php b/src/Symfony/Bridge/Doctrine/Form/DataTransformer/CollectionToArrayTransformer.php index 488d3fc2628f6..2d0fa49a02797 100644 --- a/src/Symfony/Bridge/Doctrine/Form/DataTransformer/CollectionToArrayTransformer.php +++ b/src/Symfony/Bridge/Doctrine/Form/DataTransformer/CollectionToArrayTransformer.php @@ -28,7 +28,7 @@ class CollectionToArrayTransformer implements DataTransformerInterface * * @throws TransformationFailedException */ - public function transform(mixed $collection) + public function transform(mixed $collection): mixed { if (null === $collection) { return []; @@ -54,7 +54,7 @@ public function transform(mixed $collection) * * @return Collection A collection of entities */ - public function reverseTransform(mixed $array) + public function reverseTransform(mixed $array): Collection { if ('' === $array || null === $array) { $array = []; diff --git a/src/Symfony/Bridge/Doctrine/Form/DoctrineOrmExtension.php b/src/Symfony/Bridge/Doctrine/Form/DoctrineOrmExtension.php index c2897c6d9aba8..75d7562369cce 100644 --- a/src/Symfony/Bridge/Doctrine/Form/DoctrineOrmExtension.php +++ b/src/Symfony/Bridge/Doctrine/Form/DoctrineOrmExtension.php @@ -14,6 +14,7 @@ use Doctrine\Persistence\ManagerRegistry; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractExtension; +use Symfony\Component\Form\FormTypeGuesserInterface; class DoctrineOrmExtension extends AbstractExtension { @@ -24,14 +25,14 @@ public function __construct(ManagerRegistry $registry) $this->registry = $registry; } - protected function loadTypes() + protected function loadTypes(): array { return [ new EntityType($this->registry), ]; } - protected function loadTypeGuesser() + protected function loadTypeGuesser(): ?FormTypeGuesserInterface { return new DoctrineOrmTypeGuesser($this->registry); } diff --git a/src/Symfony/Bridge/Doctrine/Form/DoctrineOrmTypeGuesser.php b/src/Symfony/Bridge/Doctrine/Form/DoctrineOrmTypeGuesser.php index 994e78b0b094e..191a853ac5c93 100644 --- a/src/Symfony/Bridge/Doctrine/Form/DoctrineOrmTypeGuesser.php +++ b/src/Symfony/Bridge/Doctrine/Form/DoctrineOrmTypeGuesser.php @@ -36,7 +36,7 @@ public function __construct(ManagerRegistry $registry) /** * {@inheritdoc} */ - public function guessType(string $class, string $property) + public function guessType(string $class, string $property): ?TypeGuess { if (!$ret = $this->getMetadata($class)) { return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\TextType', [], Guess::LOW_CONFIDENCE); @@ -94,7 +94,7 @@ public function guessType(string $class, string $property) /** * {@inheritdoc} */ - public function guessRequired(string $class, string $property) + public function guessRequired(string $class, string $property): ?ValueGuess { $classMetadatas = $this->getMetadata($class); @@ -134,7 +134,7 @@ public function guessRequired(string $class, string $property) /** * {@inheritdoc} */ - public function guessMaxLength(string $class, string $property) + public function guessMaxLength(string $class, string $property): ?ValueGuess { $ret = $this->getMetadata($class); if ($ret && isset($ret[0]->fieldMappings[$property]) && !$ret[0]->hasAssociation($property)) { @@ -155,7 +155,7 @@ public function guessMaxLength(string $class, string $property) /** * {@inheritdoc} */ - public function guessPattern(string $class, string $property) + public function guessPattern(string $class, string $property): ?ValueGuess { $ret = $this->getMetadata($class); if ($ret && isset($ret[0]->fieldMappings[$property]) && !$ret[0]->hasAssociation($property)) { diff --git a/src/Symfony/Bridge/Doctrine/Form/EventListener/MergeDoctrineCollectionListener.php b/src/Symfony/Bridge/Doctrine/Form/EventListener/MergeDoctrineCollectionListener.php index 1ec496b781c5d..f16fc64fd3ff4 100644 --- a/src/Symfony/Bridge/Doctrine/Form/EventListener/MergeDoctrineCollectionListener.php +++ b/src/Symfony/Bridge/Doctrine/Form/EventListener/MergeDoctrineCollectionListener.php @@ -27,7 +27,7 @@ */ class MergeDoctrineCollectionListener implements EventSubscriberInterface { - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { // Higher priority than core MergeCollectionListener so that this one // is called before diff --git a/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php b/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php index a25e6f85f14c4..914847c3c7804 100644 --- a/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php +++ b/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php @@ -229,15 +229,10 @@ public function configureOptions(OptionsResolver $resolver) /** * Return the default loader object. - * - * @return EntityLoaderInterface */ - abstract public function getLoader(ObjectManager $manager, object $queryBuilder, string $class); + abstract public function getLoader(ObjectManager $manager, object $queryBuilder, string $class): EntityLoaderInterface; - /** - * @return string - */ - public function getParent() + public function getParent(): string { return ChoiceType::class; } diff --git a/src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php b/src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php index 90d6ce8750887..d9293ff1f6c18 100644 --- a/src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php +++ b/src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php @@ -47,10 +47,8 @@ public function configureOptions(OptionsResolver $resolver) * Return the default loader object. * * @param QueryBuilder $queryBuilder - * - * @return ORMQueryBuilderLoader */ - public function getLoader(ObjectManager $manager, object $queryBuilder, string $class) + public function getLoader(ObjectManager $manager, object $queryBuilder, string $class): ORMQueryBuilderLoader { if (!$queryBuilder instanceof QueryBuilder) { throw new \TypeError(sprintf('Expected an instance of "%s", but got "%s".', QueryBuilder::class, get_debug_type($queryBuilder))); @@ -62,7 +60,7 @@ public function getLoader(ObjectManager $manager, object $queryBuilder, string $ /** * {@inheritdoc} */ - public function getBlockPrefix() + public function getBlockPrefix(): string { return 'entity'; } diff --git a/src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php b/src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php index 4c385ef070a6c..f9bd6e0cbcf73 100644 --- a/src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php +++ b/src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php @@ -34,10 +34,8 @@ public function __construct(LoggerInterface $logger = null, Stopwatch $stopwatch /** * {@inheritdoc} - * - * @return void */ - public function startQuery($sql, array $params = null, array $types = null) + public function startQuery($sql, array $params = null, array $types = null): void { if (null !== $this->stopwatch) { $this->stopwatch->start('doctrine', 'doctrine'); @@ -50,10 +48,8 @@ public function startQuery($sql, array $params = null, array $types = null) /** * {@inheritdoc} - * - * @return void */ - public function stopQuery() + public function stopQuery(): void { if (null !== $this->stopwatch) { $this->stopwatch->stop('doctrine'); diff --git a/src/Symfony/Bridge/Doctrine/ManagerRegistry.php b/src/Symfony/Bridge/Doctrine/ManagerRegistry.php index 7a2ad9a8d9cd0..36b2f8bde5f2c 100644 --- a/src/Symfony/Bridge/Doctrine/ManagerRegistry.php +++ b/src/Symfony/Bridge/Doctrine/ManagerRegistry.php @@ -30,20 +30,16 @@ abstract class ManagerRegistry extends AbstractManagerRegistry /** * {@inheritdoc} - * - * @return object */ - protected function getService($name) + protected function getService($name): object { return $this->container->get($name); } /** * {@inheritdoc} - * - * @return void */ - protected function resetService($name) + protected function resetService($name): void { if (!$this->container->initialized($name)) { return; diff --git a/src/Symfony/Bridge/Doctrine/Messenger/DoctrineClearEntityManagerWorkerSubscriber.php b/src/Symfony/Bridge/Doctrine/Messenger/DoctrineClearEntityManagerWorkerSubscriber.php index 5b7503c2d34f2..e06ba250b8e17 100644 --- a/src/Symfony/Bridge/Doctrine/Messenger/DoctrineClearEntityManagerWorkerSubscriber.php +++ b/src/Symfony/Bridge/Doctrine/Messenger/DoctrineClearEntityManagerWorkerSubscriber.php @@ -40,7 +40,7 @@ public function onWorkerMessageFailed() $this->clearEntityManagers(); } - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [ WorkerMessageHandledEvent::class => 'onWorkerMessageHandled', diff --git a/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php b/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php index 1f7f6afe4cc0f..b3066bd062c0e 100644 --- a/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php +++ b/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php @@ -40,7 +40,7 @@ public function __construct(EntityManagerInterface $entityManager) /** * {@inheritdoc} */ - public function getProperties(string $class, array $context = []) + public function getProperties(string $class, array $context = []): ?array { if (null === $metadata = $this->getMetadata($class)) { return null; @@ -62,7 +62,7 @@ public function getProperties(string $class, array $context = []) /** * {@inheritdoc} */ - public function getTypes(string $class, string $property, array $context = []) + public function getTypes(string $class, string $property, array $context = []): ?array { if (null === $metadata = $this->getMetadata($class)) { return null; @@ -183,7 +183,7 @@ public function getTypes(string $class, string $property, array $context = []) /** * {@inheritdoc} */ - public function isReadable(string $class, string $property, array $context = []) + public function isReadable(string $class, string $property, array $context = []): ?bool { return null; } @@ -191,7 +191,7 @@ public function isReadable(string $class, string $property, array $context = []) /** * {@inheritdoc} */ - public function isWritable(string $class, string $property, array $context = []) + public function isWritable(string $class, string $property, array $context = []): ?bool { if ( null === ($metadata = $this->getMetadata($class)) diff --git a/src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php b/src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php index a8825e75e915f..6caba7b769099 100644 --- a/src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php +++ b/src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php @@ -52,7 +52,7 @@ public function __construct(Connection $conn) /** * {@inheritdoc} */ - public function loadTokenBySeries(string $series) + public function loadTokenBySeries(string $series): PersistentTokenInterface { // the alias for lastUsed works around case insensitivity in PostgreSQL $sql = 'SELECT class, username, value, lastUsed AS last_used FROM rememberme_token WHERE series=:series'; diff --git a/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php b/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php index 72f0489c85008..a107ce37a5156 100644 --- a/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php +++ b/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php @@ -49,7 +49,7 @@ public function __construct(ManagerRegistry $registry, string $classOrAlias, str /** * {@inheritdoc} */ - public function loadUserByUsername(string $username) + public function loadUserByUsername(string $username): UserInterface { trigger_deprecation('symfony/doctrine-bridge', '5.3', 'Method "%s()" is deprecated, use loadUserByIdentifier() instead.', __METHOD__); @@ -89,7 +89,7 @@ public function loadUserByIdentifier(string $identifier): UserInterface /** * {@inheritdoc} */ - public function refreshUser(UserInterface $user) + public function refreshUser(UserInterface $user): UserInterface { $class = $this->getClass(); if (!$user instanceof $class) { @@ -123,7 +123,7 @@ public function refreshUser(UserInterface $user) /** * {@inheritdoc} */ - public function supportsClass(string $class) + public function supportsClass(string $class): bool { return $class === $this->getClass() || is_subclass_of($class, $this->getClass()); } diff --git a/src/Symfony/Bridge/Doctrine/Security/User/UserLoaderInterface.php b/src/Symfony/Bridge/Doctrine/Security/User/UserLoaderInterface.php index 551017c313315..8af4a612966a6 100644 --- a/src/Symfony/Bridge/Doctrine/Security/User/UserLoaderInterface.php +++ b/src/Symfony/Bridge/Doctrine/Security/User/UserLoaderInterface.php @@ -30,9 +30,7 @@ interface UserLoaderInterface { /** - * @return UserInterface|null - * * @deprecated since Symfony 5.3, use loadUserByIdentifier() instead */ - public function loadUserByUsername(string $username); + public function loadUserByUsername(string $username): ?UserInterface; } diff --git a/src/Symfony/Bridge/Doctrine/Test/DoctrineTestHelper.php b/src/Symfony/Bridge/Doctrine/Test/DoctrineTestHelper.php index 4821fffc616e3..2c22bb1bb45f2 100644 --- a/src/Symfony/Bridge/Doctrine/Test/DoctrineTestHelper.php +++ b/src/Symfony/Bridge/Doctrine/Test/DoctrineTestHelper.php @@ -31,10 +31,8 @@ class DoctrineTestHelper { /** * Returns an entity manager for testing. - * - * @return EntityManager */ - public static function createTestEntityManager(Configuration $config = null) + public static function createTestEntityManager(Configuration $config = null): EntityManager { if (!\extension_loaded('pdo_sqlite')) { TestCase::markTestSkipped('Extension pdo_sqlite is required.'); @@ -56,10 +54,7 @@ public static function createTestEntityManager(Configuration $config = null) return EntityManager::create($params, $config); } - /** - * @return Configuration - */ - public static function createTestConfiguration() + public static function createTestConfiguration(): Configuration { if (__CLASS__ === static::class) { trigger_deprecation('symfony/doctrine-bridge', '5.3', '"%s" is deprecated and will be removed in 6.0.', __CLASS__); @@ -75,10 +70,7 @@ public static function createTestConfiguration() return $config; } - /** - * @return Configuration - */ - public static function createTestConfigurationWithXmlLoader() + public static function createTestConfigurationWithXmlLoader(): Configuration { if (__CLASS__ === static::class) { trigger_deprecation('symfony/doctrine-bridge', '5.3', '"%s" is deprecated and will be removed in 6.0.', __CLASS__); diff --git a/src/Symfony/Bridge/Doctrine/Test/TestRepositoryFactory.php b/src/Symfony/Bridge/Doctrine/Test/TestRepositoryFactory.php index ed63b6bd03bcb..ed5548da2099a 100644 --- a/src/Symfony/Bridge/Doctrine/Test/TestRepositoryFactory.php +++ b/src/Symfony/Bridge/Doctrine/Test/TestRepositoryFactory.php @@ -30,10 +30,8 @@ class TestRepositoryFactory implements RepositoryFactory /** * {@inheritdoc} - * - * @return ObjectRepository */ - public function getRepository(EntityManagerInterface $entityManager, $entityName) + public function getRepository(EntityManagerInterface $entityManager, $entityName): ObjectRepository { if (__CLASS__ === static::class) { trigger_deprecation('symfony/doctrine-bridge', '5.3', '"%s" is deprecated and will be removed in 6.0.', __CLASS__); diff --git a/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntity.php b/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntity.php index dc848c143ca9e..ebfd5e62046d3 100644 --- a/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntity.php +++ b/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntity.php @@ -74,17 +74,15 @@ public function __construct( $this->ignoreNull = $ignoreNull ?? $this->ignoreNull; } - public function getRequiredOptions() + public function getRequiredOptions(): array { return ['fields']; } /** * The validator must be defined as a service with this name. - * - * @return string */ - public function validatedBy() + public function validatedBy(): string { return $this->service; } @@ -92,12 +90,12 @@ public function validatedBy() /** * {@inheritdoc} */ - public function getTargets() + public function getTargets(): string|array { return self::CLASS_CONSTRAINT; } - public function getDefaultOption() + public function getDefaultOption(): ?string { return 'fields'; } diff --git a/src/Symfony/Bridge/Monolog/Command/ServerLogCommand.php b/src/Symfony/Bridge/Monolog/Command/ServerLogCommand.php index 03811ab1571c7..0d2c9e89cab09 100644 --- a/src/Symfony/Bridge/Monolog/Command/ServerLogCommand.php +++ b/src/Symfony/Bridge/Monolog/Command/ServerLogCommand.php @@ -36,7 +36,7 @@ class ServerLogCommand extends Command protected static $defaultName = 'server:log'; protected static $defaultDescription = 'Start a log server that displays logs in real time'; - public function isEnabled() + public function isEnabled(): bool { if (!class_exists(ConsoleFormatter::class)) { return false; @@ -76,7 +76,7 @@ protected function configure() ; } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $filter = $input->getOption('filter'); if ($filter) { diff --git a/src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php b/src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php index 7f952e1938cd2..cba13111e1e9a 100644 --- a/src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php +++ b/src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php @@ -83,10 +83,8 @@ public function __construct(array $options = []) /** * {@inheritdoc} - * - * @return mixed */ - public function formatBatch(array $records) + public function formatBatch(array $records): mixed { foreach ($records as $key => $record) { $records[$key] = $this->format($record); @@ -97,10 +95,8 @@ public function formatBatch(array $records) /** * {@inheritdoc} - * - * @return mixed */ - public function format(array $record) + public function format(array $record): mixed { $record = $this->replacePlaceHolder($record); diff --git a/src/Symfony/Bridge/Monolog/Formatter/VarDumperFormatter.php b/src/Symfony/Bridge/Monolog/Formatter/VarDumperFormatter.php index 54988766c3a2d..d895cac1d5c6b 100644 --- a/src/Symfony/Bridge/Monolog/Formatter/VarDumperFormatter.php +++ b/src/Symfony/Bridge/Monolog/Formatter/VarDumperFormatter.php @@ -28,10 +28,8 @@ public function __construct(VarCloner $cloner = null) /** * {@inheritdoc} - * - * @return mixed */ - public function format(array $record) + public function format(array $record): mixed { $record['context'] = $this->cloner->cloneVar($record['context']); $record['extra'] = $this->cloner->cloneVar($record['extra']); @@ -41,10 +39,8 @@ public function format(array $record) /** * {@inheritdoc} - * - * @return mixed */ - public function formatBatch(array $records) + public function formatBatch(array $records): mixed { foreach ($records as $k => $record) { $record[$k] = $this->format($record); diff --git a/src/Symfony/Bridge/Monolog/Handler/ConsoleHandler.php b/src/Symfony/Bridge/Monolog/Handler/ConsoleHandler.php index 17d3c2f28d227..7a299a0316e4f 100644 --- a/src/Symfony/Bridge/Monolog/Handler/ConsoleHandler.php +++ b/src/Symfony/Bridge/Monolog/Handler/ConsoleHandler.php @@ -133,7 +133,7 @@ public function onTerminate(ConsoleTerminateEvent $event) /** * {@inheritdoc} */ - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [ ConsoleEvents::COMMAND => ['onCommand', 255], diff --git a/src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php b/src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php index d9ed81205a6e3..e5b8558b32226 100644 --- a/src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php +++ b/src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php @@ -126,10 +126,7 @@ private function sendToElasticsearch(array $records) $this->wait(false); } - /** - * @return array - */ - public function __sleep() + public function __sleep(): array { throw new \BadMethodCallException('Cannot serialize '.__CLASS__); } diff --git a/src/Symfony/Bridge/Monolog/Logger.php b/src/Symfony/Bridge/Monolog/Logger.php index 4643f5b6d7598..2b5f312053048 100644 --- a/src/Symfony/Bridge/Monolog/Logger.php +++ b/src/Symfony/Bridge/Monolog/Logger.php @@ -25,7 +25,7 @@ class Logger extends BaseLogger implements DebugLoggerInterface, ResetInterface /** * {@inheritdoc} */ - public function getLogs(Request $request = null) + public function getLogs(Request $request = null): array { if ($logger = $this->getDebugLogger()) { return $logger->getLogs($request); @@ -37,7 +37,7 @@ public function getLogs(Request $request = null) /** * {@inheritdoc} */ - public function countErrors(Request $request = null) + public function countErrors(Request $request = null): int { if ($logger = $this->getDebugLogger()) { return $logger->countErrors($request); diff --git a/src/Symfony/Bridge/Monolog/Processor/ConsoleCommandProcessor.php b/src/Symfony/Bridge/Monolog/Processor/ConsoleCommandProcessor.php index 2891f4f2f4916..62c75d2e11190 100644 --- a/src/Symfony/Bridge/Monolog/Processor/ConsoleCommandProcessor.php +++ b/src/Symfony/Bridge/Monolog/Processor/ConsoleCommandProcessor.php @@ -60,7 +60,7 @@ public function addCommandData(ConsoleEvent $event) } } - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [ ConsoleEvents::COMMAND => ['addCommandData', 1], diff --git a/src/Symfony/Bridge/Monolog/Processor/DebugProcessor.php b/src/Symfony/Bridge/Monolog/Processor/DebugProcessor.php index 98b1d229220fe..3ecaa47bfc11c 100644 --- a/src/Symfony/Bridge/Monolog/Processor/DebugProcessor.php +++ b/src/Symfony/Bridge/Monolog/Processor/DebugProcessor.php @@ -68,7 +68,7 @@ public function __invoke(array $record) /** * {@inheritdoc} */ - public function getLogs(Request $request = null) + public function getLogs(Request $request = null): array { if (null !== $request) { return $this->records[spl_object_hash($request)] ?? []; @@ -84,7 +84,7 @@ public function getLogs(Request $request = null) /** * {@inheritdoc} */ - public function countErrors(Request $request = null) + public function countErrors(Request $request = null): int { if (null !== $request) { return $this->errorCount[spl_object_hash($request)] ?? 0; diff --git a/src/Symfony/Bridge/ProxyManager/LazyProxy/Instantiator/RuntimeInstantiator.php b/src/Symfony/Bridge/ProxyManager/LazyProxy/Instantiator/RuntimeInstantiator.php index 7dc8d3d65b7c7..003986b8d00fc 100644 --- a/src/Symfony/Bridge/ProxyManager/LazyProxy/Instantiator/RuntimeInstantiator.php +++ b/src/Symfony/Bridge/ProxyManager/LazyProxy/Instantiator/RuntimeInstantiator.php @@ -38,7 +38,7 @@ public function __construct() /** * {@inheritdoc} */ - public function instantiateProxy(ContainerInterface $container, Definition $definition, string $id, callable $realInstantiator) + public function instantiateProxy(ContainerInterface $container, Definition $definition, string $id, callable $realInstantiator): object { return $this->factory->createProxy( $this->factory->getGenerator()->getProxifiedClass($definition), diff --git a/src/Symfony/Bridge/Twig/AppVariable.php b/src/Symfony/Bridge/Twig/AppVariable.php index fc647e0705b89..0e88ab95606b2 100644 --- a/src/Symfony/Bridge/Twig/AppVariable.php +++ b/src/Symfony/Bridge/Twig/AppVariable.php @@ -56,7 +56,7 @@ public function setDebug(bool $debug) * * @throws \RuntimeException When the TokenStorage is not available */ - public function getToken() + public function getToken(): ?TokenInterface { if (null === $tokenStorage = $this->tokenStorage) { throw new \RuntimeException('The "app.token" variable is not available.'); @@ -72,7 +72,7 @@ public function getToken() * * @see TokenInterface::getUser() */ - public function getUser() + public function getUser(): ?object { if (null === $tokenStorage = $this->tokenStorage) { throw new \RuntimeException('The "app.user" variable is not available.'); @@ -92,7 +92,7 @@ public function getUser() * * @return Request|null The HTTP request object */ - public function getRequest() + public function getRequest(): ?Request { if (null === $this->requestStack) { throw new \RuntimeException('The "app.request" variable is not available.'); @@ -106,7 +106,7 @@ public function getRequest() * * @return Session|null The session */ - public function getSession() + public function getSession(): ?Session { if (null === $this->requestStack) { throw new \RuntimeException('The "app.session" variable is not available.'); @@ -121,7 +121,7 @@ public function getSession() * * @return string The current environment string (e.g 'dev') */ - public function getEnvironment() + public function getEnvironment(): string { if (null === $this->environment) { throw new \RuntimeException('The "app.environment" variable is not available.'); @@ -135,7 +135,7 @@ public function getEnvironment() * * @return bool The current debug mode */ - public function getDebug() + public function getDebug(): bool { if (null === $this->debug) { throw new \RuntimeException('The "app.debug" variable is not available.'); @@ -152,7 +152,7 @@ public function getDebug() * * @return array */ - public function getFlashes(string|array $types = null) + public function getFlashes(string|array $types = null): array { try { if (null === $session = $this->getSession()) { diff --git a/src/Symfony/Bridge/Twig/Command/DebugCommand.php b/src/Symfony/Bridge/Twig/Command/DebugCommand.php index c782fb23d2637..8a5a13be0fdb1 100644 --- a/src/Symfony/Bridge/Twig/Command/DebugCommand.php +++ b/src/Symfony/Bridge/Twig/Command/DebugCommand.php @@ -86,7 +86,7 @@ protected function configure() ; } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $name = $input->getArgument('name'); diff --git a/src/Symfony/Bridge/Twig/Command/LintCommand.php b/src/Symfony/Bridge/Twig/Command/LintCommand.php index 53e1d0bb583c4..d5beaeab89c8b 100644 --- a/src/Symfony/Bridge/Twig/Command/LintCommand.php +++ b/src/Symfony/Bridge/Twig/Command/LintCommand.php @@ -81,7 +81,7 @@ protected function configure() ; } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $filenames = $input->getArgument('filename'); diff --git a/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php b/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php index c264c633abb7e..1b965ab2434d9 100644 --- a/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php +++ b/src/Symfony/Bridge/Twig/Form/TwigRendererEngine.php @@ -40,7 +40,7 @@ public function __construct(array $defaultThemes, Environment $environment) /** * {@inheritdoc} */ - public function renderBlock(FormView $view, mixed $resource, string $blockName, array $variables = []) + public function renderBlock(FormView $view, mixed $resource, string $blockName, array $variables = []): string { $cacheKey = $view->vars[self::CACHE_KEY_VAR]; @@ -72,7 +72,7 @@ public function renderBlock(FormView $view, mixed $resource, string $blockName, * * @return bool True if the resource could be loaded, false otherwise */ - protected function loadResourceForBlockName(string $cacheKey, FormView $view, string $blockName) + protected function loadResourceForBlockName(string $cacheKey, FormView $view, string $blockName): bool { // The caller guarantees that $this->resources[$cacheKey][$block] is // not set, but it doesn't have to check whether $this->resources[$cacheKey] diff --git a/src/Symfony/Bridge/Twig/Mime/NotificationEmail.php b/src/Symfony/Bridge/Twig/Mime/NotificationEmail.php index 8492f3dee1ba1..604e10b21339a 100644 --- a/src/Symfony/Bridge/Twig/Mime/NotificationEmail.php +++ b/src/Symfony/Bridge/Twig/Mime/NotificationEmail.php @@ -80,7 +80,7 @@ public function markAsPublic(): self /** * @return $this */ - public function markdown(string $content) + public function markdown(string $content): static { if (!class_exists(MarkdownExtension::class)) { throw new \LogicException(sprintf('You cannot use "%s" if the Markdown Twig extension is not available; try running "composer require twig/markdown-extra".', __METHOD__)); @@ -94,7 +94,7 @@ public function markdown(string $content) /** * @return $this */ - public function content(string $content, bool $raw = false) + public function content(string $content, bool $raw = false): static { $this->context['content'] = $content; $this->context['raw'] = $raw; @@ -105,7 +105,7 @@ public function content(string $content, bool $raw = false) /** * @return $this */ - public function action(string $text, string $url) + public function action(string $text, string $url): static { $this->context['action_text'] = $text; $this->context['action_url'] = $url; @@ -116,7 +116,7 @@ public function action(string $text, string $url) /** * @return $this */ - public function importance(string $importance) + public function importance(string $importance): static { $this->context['importance'] = $importance; @@ -126,7 +126,7 @@ public function importance(string $importance) /** * @return $this */ - public function exception(\Throwable|FlattenException $exception) + public function exception(\Throwable|FlattenException $exception): static { $exceptionAsString = $this->getExceptionAsString($exception); @@ -144,7 +144,7 @@ public function exception(\Throwable|FlattenException $exception) /** * @return $this */ - public function theme(string $theme) + public function theme(string $theme): static { $this->theme = $theme; diff --git a/src/Symfony/Bridge/Twig/Mime/TemplatedEmail.php b/src/Symfony/Bridge/Twig/Mime/TemplatedEmail.php index 6dd9202de8fc7..aceef09ebbaf6 100644 --- a/src/Symfony/Bridge/Twig/Mime/TemplatedEmail.php +++ b/src/Symfony/Bridge/Twig/Mime/TemplatedEmail.php @@ -25,7 +25,7 @@ class TemplatedEmail extends Email /** * @return $this */ - public function textTemplate(?string $template) + public function textTemplate(?string $template): static { $this->textTemplate = $template; @@ -35,7 +35,7 @@ public function textTemplate(?string $template) /** * @return $this */ - public function htmlTemplate(?string $template) + public function htmlTemplate(?string $template): static { $this->htmlTemplate = $template; @@ -55,7 +55,7 @@ public function getHtmlTemplate(): ?string /** * @return $this */ - public function context(array $context) + public function context(array $context): static { $this->context = $context; diff --git a/src/Symfony/Bridge/Twig/NodeVisitor/Scope.php b/src/Symfony/Bridge/Twig/NodeVisitor/Scope.php index 3b20b2fd6096a..b7a998d24f634 100644 --- a/src/Symfony/Bridge/Twig/NodeVisitor/Scope.php +++ b/src/Symfony/Bridge/Twig/NodeVisitor/Scope.php @@ -30,7 +30,7 @@ public function __construct(self $parent = null) * * @return self */ - public function enter() + public function enter(): \Symfony\Bridge\Twig\NodeVisitor\Scope { return new self($this); } @@ -40,7 +40,7 @@ public function enter() * * @return self|null */ - public function leave() + public function leave(): ?\Symfony\Bridge\Twig\NodeVisitor\Scope { $this->left = true; @@ -54,7 +54,7 @@ public function leave() * * @throws \LogicException */ - public function set(string $key, mixed $value) + public function set(string $key, mixed $value): static { if ($this->left) { throw new \LogicException('Left scope is not mutable.'); @@ -70,7 +70,7 @@ public function set(string $key, mixed $value) * * @return bool */ - public function has(string $key) + public function has(string $key): bool { if (\array_key_exists($key, $this->data)) { return true; @@ -88,7 +88,7 @@ public function has(string $key) * * @return mixed */ - public function get(string $key, mixed $default = null) + public function get(string $key, mixed $default = null): mixed { if (\array_key_exists($key, $this->data)) { return $this->data[$key]; diff --git a/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php b/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php index e79ec697e0f50..3c7a61cfcc48a 100644 --- a/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php +++ b/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php @@ -87,7 +87,7 @@ protected function extractTemplate(string $template, MessageCatalogue $catalogue /** * @return bool */ - protected function canBeExtracted(string $file) + protected function canBeExtracted(string $file): bool { return $this->isFile($file) && 'twig' === pathinfo($file, \PATHINFO_EXTENSION); } @@ -95,7 +95,7 @@ protected function canBeExtracted(string $file) /** * {@inheritdoc} */ - protected function extractFromDirectory($directory) + protected function extractFromDirectory($directory): iterable { $finder = new Finder(); diff --git a/src/Symfony/Bridge/Twig/UndefinedCallableHandler.php b/src/Symfony/Bridge/Twig/UndefinedCallableHandler.php index 608bbaa8e30ad..360a386faedec 100644 --- a/src/Symfony/Bridge/Twig/UndefinedCallableHandler.php +++ b/src/Symfony/Bridge/Twig/UndefinedCallableHandler.php @@ -71,7 +71,7 @@ class UndefinedCallableHandler /** * @return TwigFilter|false */ - public static function onUndefinedFilter(string $name) + public static function onUndefinedFilter(string $name): TwigFilter|false { if (!isset(self::FILTER_COMPONENTS[$name])) { return false; @@ -83,7 +83,7 @@ public static function onUndefinedFilter(string $name) /** * @return TwigFunction|false */ - public static function onUndefinedFunction(string $name) + public static function onUndefinedFunction(string $name): TwigFunction|false { if (!isset(self::FUNCTION_COMPONENTS[$name])) { return false;