From e85e459e136e9137fd3b4d74aca1243ca6e8ec36 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 29 Jun 2021 23:31:02 +0200 Subject: [PATCH] [FrameworkBundle] add union types --- .../CacheWarmer/CachePoolClearerCacheWarmer.php | 2 +- .../Command/EventDispatcherDebugCommand.php | 2 +- .../FrameworkBundle/Console/Application.php | 6 +++--- .../Console/Descriptor/Descriptor.php | 16 +++------------- .../Console/Descriptor/JsonDescriptor.php | 2 +- .../Controller/AbstractController.php | 2 +- .../Controller/ControllerResolver.php | 7 ++----- .../DataCollector/RouterDataCollector.php | 4 +--- .../Compiler/AddDebugLogProcessorPass.php | 2 +- .../DependencyInjection/Configuration.php | 2 +- .../FrameworkBundle/HttpCache/HttpCache.php | 4 ++-- .../Bundle/FrameworkBundle/KernelBrowser.php | 2 +- .../Routing/AnnotatedRouteControllerLoader.php | 4 +--- .../Bundle/FrameworkBundle/Routing/Router.php | 4 ++-- .../FrameworkBundle/Secrets/SodiumVault.php | 6 +++--- .../Test/BrowserKitAssertionsTrait.php | 2 +- .../FrameworkBundle/Test/TestContainer.php | 4 ++-- .../FrameworkBundle/Translation/Translator.php | 4 +--- 18 files changed, 28 insertions(+), 47 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/CachePoolClearerCacheWarmer.php b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/CachePoolClearerCacheWarmer.php index fa87952621c87..0e5997996004f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/CachePoolClearerCacheWarmer.php +++ b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/CachePoolClearerCacheWarmer.php @@ -39,7 +39,7 @@ public function __construct(Psr6CacheClearer $poolClearer, array $pools = []) * * @return string[] */ - public function warmUp($cacheDirectory): array + public function warmUp(string $cacheDirectory): array { foreach ($this->pools as $pool) { if ($this->poolClearer->hasPool($pool)) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/EventDispatcherDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/EventDispatcherDebugCommand.php index 70d2e9cd59a70..523c481a4ba06 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/EventDispatcherDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/EventDispatcherDebugCommand.php @@ -120,7 +120,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 0; } - private function searchForEvent(EventDispatcherInterface $dispatcher, $needle): array + private function searchForEvent(EventDispatcherInterface $dispatcher, string $needle): array { $output = []; $lcNeedle = strtolower($needle); diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php index 0ce23600686dc..490d8cbb61f3e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php @@ -109,7 +109,7 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI /** * {@inheritdoc} */ - public function find($name) + public function find(string $name) { $this->registerCommands(); @@ -119,7 +119,7 @@ public function find($name) /** * {@inheritdoc} */ - public function get($name) + public function get(string $name) { $this->registerCommands(); @@ -135,7 +135,7 @@ public function get($name) /** * {@inheritdoc} */ - public function all($namespace = null) + public function all(string $namespace = null) { $this->registerCommands(); diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php index 4601710d35e93..1e88cddc307f7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/Descriptor.php @@ -129,7 +129,7 @@ abstract protected function describeContainerDefinition(Definition $definition, abstract protected function describeContainerAlias(Alias $alias, array $options = [], ContainerBuilder $builder = null); - abstract protected function describeContainerParameter($parameter, array $options = []); + abstract protected function describeContainerParameter(mixed $parameter, array $options = []); abstract protected function describeContainerEnvVars(array $envs, array $options = []); @@ -141,19 +141,9 @@ abstract protected function describeContainerEnvVars(array $envs, array $options */ abstract protected function describeEventDispatcherListeners(EventDispatcherInterface $eventDispatcher, array $options = []); - /** - * Describes a callable. - * - * @param mixed $callable - */ - abstract protected function describeCallable($callable, array $options = []); + abstract protected function describeCallable(mixed $callable, array $options = []); - /** - * Formats a value as string. - * - * @param mixed $value - */ - protected function formatValue($value): string + protected function formatValue(mixed $value): string { if (\is_object($value)) { return sprintf('object(%s)', \get_class($value)); diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php index 30e62e6a49237..e1067f1fdab8b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php @@ -139,7 +139,7 @@ protected function describeEventDispatcherListeners(EventDispatcherInterface $ev $this->writeData($this->getEventDispatcherListenersData($eventDispatcher, $options), $options); } - protected function describeCallable($callable, array $options = []) + protected function describeCallable(mixed $callable, array $options = []) { $this->writeData($this->getCallableData($callable), $options); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php b/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php index 48c4aba49ad9c..bad069eaf3e18 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php @@ -168,7 +168,7 @@ protected function redirectToRoute(string $route, array $parameters = [], int $s /** * Returns a JsonResponse that uses the serializer component if enabled, or json_encode. */ - protected function json($data, int $status = 200, array $headers = [], array $context = []): JsonResponse + protected function json(mixed $data, int $status = 200, array $headers = [], array $context = []): JsonResponse { if ($this->container->has('serializer')) { $json = $this->container->get('serializer')->serialize($data, 'json', array_merge([ diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerResolver.php b/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerResolver.php index 859d1c200ed4e..0539c1ee734ca 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerResolver.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerResolver.php @@ -24,13 +24,10 @@ class ControllerResolver extends ContainerControllerResolver /** * {@inheritdoc} */ - protected function instantiateController($class): object + protected function instantiateController(string $class): object { - return $this->configureController(parent::instantiateController($class), $class); - } + $controller = parent::instantiateController($class); - private function configureController($controller, string $class): object - { if ($controller instanceof ContainerAwareInterface) { $controller->setContainer($this->container); } diff --git a/src/Symfony/Bundle/FrameworkBundle/DataCollector/RouterDataCollector.php b/src/Symfony/Bundle/FrameworkBundle/DataCollector/RouterDataCollector.php index 0acdc61a3db18..ccb61b128627f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DataCollector/RouterDataCollector.php +++ b/src/Symfony/Bundle/FrameworkBundle/DataCollector/RouterDataCollector.php @@ -16,15 +16,13 @@ use Symfony\Component\HttpKernel\DataCollector\RouterDataCollector as BaseRouterDataCollector; /** - * RouterDataCollector. - * * @author Fabien Potencier * * @final */ class RouterDataCollector extends BaseRouterDataCollector { - public function guessRoute(Request $request, $controller) + public function guessRoute(Request $request, mixed $controller) { if (\is_array($controller)) { $controller = $controller[0]; diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddDebugLogProcessorPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddDebugLogProcessorPass.php index 51b29755460a3..a1bf0a80eadb0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddDebugLogProcessorPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddDebugLogProcessorPass.php @@ -34,7 +34,7 @@ public function process(ContainerBuilder $container) $definition->addMethodCall('pushProcessor', [new Reference('debug.log_processor')]); } - public static function configureLogger($logger) + public static function configureLogger(mixed $logger) { if (\is_object($logger) && method_exists($logger, 'removeDebugLogger') && \in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) { $logger->removeDebugLogger(); diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 2f0d24dd858e9..68b6db95ee874 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -960,7 +960,7 @@ private function addAnnotationsSection(ArrayNodeDefinition $rootNode, callable $ ; } - private function addSerializerSection(ArrayNodeDefinition $rootNode, callable $enableIfStandalone, $willBeAvailable) + private function addSerializerSection(ArrayNodeDefinition $rootNode, callable $enableIfStandalone, callable $willBeAvailable) { $rootNode ->children() diff --git a/src/Symfony/Bundle/FrameworkBundle/HttpCache/HttpCache.php b/src/Symfony/Bundle/FrameworkBundle/HttpCache/HttpCache.php index 35ea73c235771..5028cadc818a0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/HttpCache/HttpCache.php +++ b/src/Symfony/Bundle/FrameworkBundle/HttpCache/HttpCache.php @@ -35,9 +35,9 @@ class HttpCache extends BaseHttpCache private $options; /** - * @param string|StoreInterface $cache The cache directory (default used if null) or the storage instance + * @param $cache The cache directory (default used if null) or the storage instance */ - public function __construct(KernelInterface $kernel, $cache = null, SurrogateInterface $surrogate = null, array $options = null) + public function __construct(KernelInterface $kernel, string|StoreInterface $cache = null, SurrogateInterface $surrogate = null, array $options = null) { $this->kernel = $kernel; $this->surrogate = $surrogate; diff --git a/src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php b/src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php index ee75a054e68d9..b6231535b48d2 100644 --- a/src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php +++ b/src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php @@ -112,7 +112,7 @@ public function enableReboot() /** * @param UserInterface $user */ - public function loginUser($user, string $firewallContext = 'main'): self + public function loginUser(object $user, string $firewallContext = 'main'): self { if (!interface_exists(UserInterface::class)) { throw new \LogicException(sprintf('"%s" requires symfony/security-core to be installed.', __METHOD__)); diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/AnnotatedRouteControllerLoader.php b/src/Symfony/Bundle/FrameworkBundle/Routing/AnnotatedRouteControllerLoader.php index 51419c8914988..e708b70ca712e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Routing/AnnotatedRouteControllerLoader.php +++ b/src/Symfony/Bundle/FrameworkBundle/Routing/AnnotatedRouteControllerLoader.php @@ -24,10 +24,8 @@ class AnnotatedRouteControllerLoader extends AnnotationClassLoader { /** * Configures the _controller default parameter of a given Route instance. - * - * @param mixed $annot The annotation class instance */ - protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annot) + protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, object $annot) { if ('__invoke' === $method->getName()) { $route->setDefault('_controller', $class->getName()); diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php b/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php index 23d194567959d..c6afbff007341 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php +++ b/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php @@ -40,7 +40,7 @@ class Router extends BaseRouter implements WarmableInterface, ServiceSubscriberI /** * @param mixed $resource The main resource to load */ - public function __construct(ContainerInterface $container, $resource, array $options = [], RequestContext $context = null, ContainerInterface $parameters = null, LoggerInterface $logger = null, string $defaultLocale = null) + public function __construct(ContainerInterface $container, mixed $resource, array $options = [], RequestContext $context = null, ContainerInterface $parameters = null, LoggerInterface $logger = null, string $defaultLocale = null) { $this->container = $container; $this->resource = $resource; @@ -154,7 +154,7 @@ private function resolveParameters(RouteCollection $collection) * @throws ParameterNotFoundException When a placeholder does not exist as a container parameter * @throws RuntimeException When a container value is not a string or a numeric value */ - private function resolve($value) + private function resolve(mixed $value) { if (\is_array($value)) { foreach ($value as $key => $val) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Secrets/SodiumVault.php b/src/Symfony/Bundle/FrameworkBundle/Secrets/SodiumVault.php index 3448d1a0ea9cb..f18485dbfea74 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Secrets/SodiumVault.php +++ b/src/Symfony/Bundle/FrameworkBundle/Secrets/SodiumVault.php @@ -29,10 +29,10 @@ class SodiumVault extends AbstractVault implements EnvVarLoaderInterface private $secretsDir; /** - * @param string|\Stringable|null $decryptionKey A string or a stringable object that defines the private key to use to decrypt the vault - * or null to store generated keys in the provided $secretsDir + * @param $decryptionKey A string or a stringable object that defines the private key to use to decrypt the vault + * or null to store generated keys in the provided $secretsDir */ - public function __construct(string $secretsDir, $decryptionKey = null) + public function __construct(string $secretsDir, string|\Stringable $decryptionKey = null) { if (null !== $decryptionKey && !\is_string($decryptionKey) && !$decryptionKey instanceof \Stringable) { throw new \TypeError(sprintf('Decryption key should be a string or an object that implements the __toString() method, "%s" given.', get_debug_type($decryptionKey))); diff --git a/src/Symfony/Bundle/FrameworkBundle/Test/BrowserKitAssertionsTrait.php b/src/Symfony/Bundle/FrameworkBundle/Test/BrowserKitAssertionsTrait.php index 8caa19fa1f443..62bd1b79acc05 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Test/BrowserKitAssertionsTrait.php +++ b/src/Symfony/Bundle/FrameworkBundle/Test/BrowserKitAssertionsTrait.php @@ -117,7 +117,7 @@ public static function assertRequestAttributeValueSame(string $name, string $exp self::assertThat(self::getRequest(), new ResponseConstraint\RequestAttributeValueSame($name, $expectedValue), $message); } - public static function assertRouteSame($expectedRoute, array $parameters = [], string $message = ''): void + public static function assertRouteSame(string $expectedRoute, array $parameters = [], string $message = ''): void { $constraint = new ResponseConstraint\RequestAttributeValueSame('_route', $expectedRoute); $constraints = []; diff --git a/src/Symfony/Bundle/FrameworkBundle/Test/TestContainer.php b/src/Symfony/Bundle/FrameworkBundle/Test/TestContainer.php index 03ce3fa005bfc..f5bb77c20acdb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Test/TestContainer.php +++ b/src/Symfony/Bundle/FrameworkBundle/Test/TestContainer.php @@ -82,7 +82,7 @@ public function hasParameter(string $name): bool /** * {@inheritdoc} */ - public function setParameter(string $name, $value) + public function setParameter(string $name, mixed $value) { $this->getPublicContainer()->setParameter($name, $value); } @@ -90,7 +90,7 @@ public function setParameter(string $name, $value) /** * {@inheritdoc} */ - public function set(string $id, $service) + public function set(string $id, mixed $service) { $this->getPublicContainer()->set($id, $service); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php b/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php index 08c920fd951c6..2677d537c1e8c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php +++ b/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php @@ -20,8 +20,6 @@ use Symfony\Component\Translation\Translator as BaseTranslator; /** - * Translator. - * * @author Fabien Potencier */ class Translator extends BaseTranslator implements WarmableInterface @@ -119,7 +117,7 @@ public function warmUp(string $cacheDir) return []; } - public function addResource(string $format, $resource, string $locale, string $domain = null) + public function addResource(string $format, mixed $resource, string $locale, string $domain = null) { if ($this->resourceFiles) { $this->addResourceFiles();