Skip to content

[FrameworkBundle] add union types #41907

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Bundle/FrameworkBundle/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
/**
* {@inheritdoc}
*/
public function find($name)
public function find(string $name)
{
$this->registerCommands();

Expand All @@ -119,7 +119,7 @@ public function find($name)
/**
* {@inheritdoc}
*/
public function get($name)
public function get(string $name)
{
$this->registerCommands();

Expand All @@ -135,7 +135,7 @@ public function get($name)
/**
* {@inheritdoc}
*/
public function all($namespace = null)
public function all(string $namespace = null)
{
$this->registerCommands();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []);

Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
use Symfony\Component\HttpKernel\DataCollector\RouterDataCollector as BaseRouterDataCollector;

/**
* RouterDataCollector.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bundle/FrameworkBundle/HttpCache/HttpCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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__));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bundle/FrameworkBundle/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Bundle/FrameworkBundle/Secrets/SodiumVault.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bundle/FrameworkBundle/Test/TestContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ 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);
}

/**
* {@inheritdoc}
*/
public function set(string $id, $service)
public function set(string $id, mixed $service)
{
$this->getPublicContainer()->set($id, $service);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
use Symfony\Component\Translation\Translator as BaseTranslator;

/**
* Translator.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class Translator extends BaseTranslator implements WarmableInterface
Expand Down Expand Up @@ -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();
Expand Down