Skip to content

[DependencyInjection] add union types #41902

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
Jun 29, 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 @@ -28,7 +28,7 @@ final class BoundArgument implements ArgumentInterface
private $type;
private $file;

public function __construct($value, bool $trackUsage = true, int $type = 0, string $file = null)
public function __construct(mixed $value, bool $trackUsage = true, int $type = 0, string $file = null)
{
$this->value = $value;
if ($trackUsage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ class RewindableGenerator implements \IteratorAggregate, \Countable
private $generator;
private $count;

/**
* @param int|callable $count
*/
public function __construct(callable $generator, $count)
public function __construct(callable $generator, int|callable $count)
{
$this->generator = $generator;
$this->count = $count;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(\Closure $factory, array $serviceMap, array $service
*
* @return mixed
*/
public function get($id)
public function get(string $id)
{
return isset($this->serviceMap[$id]) ? ($this->factory)(...$this->serviceMap[$id]) : parent::get($id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ServiceLocatorArgument implements ArgumentInterface
/**
* @param Reference[]|TaggedIteratorArgument $values
*/
public function __construct($values = [])
public function __construct(array|TaggedIteratorArgument $values = [])
{
if ($values instanceof TaggedIteratorArgument) {
$this->taggedIteratorArgument = $values;
Expand Down
13 changes: 3 additions & 10 deletions src/Symfony/Component/DependencyInjection/ChildDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ public function getParent()
/**
* Sets the Definition to inherit from.
*
* @param string $parent
*
* @return $this
*/
public function setParent($parent)
public function setParent(string $parent)
{
$this->parent = $parent;

Expand All @@ -61,13 +59,11 @@ public function setParent($parent)
* If replaceArgument() has been used to replace an argument, this method
* will return the replacement value.
*
* @param int|string $index
*
* @return mixed The argument value
*
* @throws OutOfBoundsException When the argument does not exist
*/
public function getArgument($index)
public function getArgument(int|string $index)
{
if (\array_key_exists('index_'.$index, $this->arguments)) {
return $this->arguments['index_'.$index];
Expand All @@ -84,14 +80,11 @@ public function getArgument($index)
* certain conventions when you want to overwrite the arguments of the
* parent definition, otherwise your arguments will only be appended.
*
* @param int|string $index
* @param mixed $value
*
* @return $this
*
* @throws InvalidArgumentException when $index isn't an integer
*/
public function replaceArgument($index, $value)
public function replaceArgument(int|string $index, mixed $value)
{
if (\is_int($index)) {
$this->arguments['index_'.$index] = $value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,9 @@ protected function inExpression(bool $reset = true): bool
/**
* Processes a value found in a definition tree.
*
* @param mixed $value
*
* @return mixed The processed value
*/
protected function processValue($value, bool $isRoot = false)
protected function processValue(mixed $value, bool $isRoot = false)
{
if (\is_array($value)) {
foreach ($value as $k => $v) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(string $tagName = 'container.private')
/**
* {@inheritdoc}
*/
protected function processValue($value, bool $isRoot = false)
protected function processValue(mixed $value, bool $isRoot = false)
{
if ($value instanceof Reference && isset($this->aliases[$id = (string) $value])) {
return new Reference($this->aliases[$id], $value->getInvalidBehavior());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function process(ContainerBuilder $container)
}
}

protected function processValue($value, bool $isRoot = false)
protected function processValue(mixed $value, bool $isRoot = false)
{
$lazy = $this->lazy;
$inExpression = $this->inExpression();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function process(ContainerBuilder $container): void
parent::process($container);
}

protected function processValue($value, bool $isRoot = false)
protected function processValue(mixed $value, bool $isRoot = false)
{
if (!$value instanceof Definition
|| !$value->isAutoconfigured()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function process(ContainerBuilder $container)
/**
* {@inheritdoc}
*/
protected function processValue($value, bool $isRoot = false)
protected function processValue(mixed $value, bool $isRoot = false)
{
try {
return $this->doProcessValue($value, $isRoot);
Expand All @@ -87,10 +87,7 @@ protected function processValue($value, bool $isRoot = false)
}
}

/**
* @return mixed
*/
private function doProcessValue($value, bool $isRoot = false)
private function doProcessValue(mixed $value, bool $isRoot = false): mixed
{
if ($value instanceof TypedReference) {
if ($ref = $this->getAutowiredReference($value)) {
Expand Down Expand Up @@ -408,7 +405,7 @@ private function set(string $type, string $id)
$this->ambiguousServiceTypes[$type][] = $id;
}

private function createTypeNotFoundMessageCallback(TypedReference $reference, string $label): callable
private function createTypeNotFoundMessageCallback(TypedReference $reference, string $label): \Closure
{
if (null === $this->typesClone->container) {
$this->typesClone->container = new ContainerBuilder($this->container->getParameterBag());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class AutowireRequiredMethodsPass extends AbstractRecursivePass
/**
* {@inheritdoc}
*/
protected function processValue($value, bool $isRoot = false)
protected function processValue(mixed $value, bool $isRoot = false)
{
$value = parent::processValue($value, $isRoot);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AutowireRequiredPropertiesPass extends AbstractRecursivePass
/**
* {@inheritdoc}
*/
protected function processValue($value, bool $isRoot = false)
protected function processValue(mixed $value, bool $isRoot = false)
{
$value = parent::processValue($value, $isRoot);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(bool $throwExceptions = true)
/**
* {@inheritdoc}
*/
protected function processValue($value, bool $isRoot = false)
protected function processValue(mixed $value, bool $isRoot = false)
{
if (!$value instanceof Definition) {
return parent::processValue($value, $isRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function process(ContainerBuilder $container)
}
}

protected function processValue($value, bool $isRoot = false)
protected function processValue(mixed $value, bool $isRoot = false)
{
if (!$value instanceof Reference) {
return parent::processValue($value, $isRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
class CheckReferenceValidityPass extends AbstractRecursivePass
{
protected function processValue($value, bool $isRoot = false)
protected function processValue(mixed $value, bool $isRoot = false)
{
if ($isRoot && $value instanceof Definition && ($value->isSynthetic() || $value->isAbstract())) {
return $value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function __construct(bool $autoload = false, array $skippedIds = [])
/**
* {@inheritdoc}
*/
protected function processValue($value, bool $isRoot = false)
protected function processValue(mixed $value, bool $isRoot = false)
{
if (isset($this->skippedIds[$this->currentId])) {
return $value;
Expand Down Expand Up @@ -158,7 +158,7 @@ private function checkTypeDeclarations(Definition $checkedDefinition, \Reflectio
/**
* @throws InvalidParameterTypeException When a parameter is not compatible with the declared type
*/
private function checkType(Definition $checkedDefinition, $value, \ReflectionParameter $parameter, ?string $envPlaceholderUniquePrefix, \ReflectionType $reflectionType = null): void
private function checkType(Definition $checkedDefinition, mixed $value, \ReflectionParameter $parameter, ?string $envPlaceholderUniquePrefix, \ReflectionType $reflectionType = null): void
{
$reflectionType = $reflectionType ?? $parameter->getType();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function process(ContainerBuilder $container)
}
}

protected function processValue($value, bool $isRoot = false)
protected function processValue(mixed $value, bool $isRoot = false)
{
if ($value instanceof Reference && $this->innerId === (string) $value) {
return new Reference($this->currentId, $value->getInvalidBehavior());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DefinitionErrorExceptionPass extends AbstractRecursivePass
/**
* {@inheritdoc}
*/
protected function processValue($value, bool $isRoot = false)
protected function processValue(mixed $value, bool $isRoot = false)
{
if (!$value instanceof Definition || !$value->hasErrors()) {
return parent::processValue($value, $isRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function process(ContainerBuilder $container)
/**
* {@inheritdoc}
*/
protected function processValue($value, bool $isRoot = false)
protected function processValue(mixed $value, bool $isRoot = false)
{
if ($value instanceof ArgumentInterface) {
// Reference found in ArgumentInterface::getValues() are not inlineable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public function compile(bool $resolveEnvPlaceholders = false)
/**
* {@inheritdoc}
*/
public function resolveEnvPlaceholders($value, $format = null, array &$usedEnvs = null)
public function resolveEnvPlaceholders(mixed $value, string|bool|null $format = null, array &$usedEnvs = null)
{
if (true !== $format || !\is_string($value)) {
return parent::resolveEnvPlaceholders($value, $format, $usedEnvs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ trait PriorityTaggedServiceTrait
* @see https://bugs.php.net/53710
* @see https://bugs.php.net/60926
*
* @param string|TaggedIteratorArgument $tagName
*
* @return Reference[]
*/
private function findAndSortTaggedServices($tagName, ContainerBuilder $container): array
private function findAndSortTaggedServices(string|TaggedIteratorArgument $tagName, ContainerBuilder $container): array
{
$indexAttribute = $defaultIndexMethod = $needsIndexes = $defaultPriorityMethod = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
class RegisterServiceSubscribersPass extends AbstractRecursivePass
{
protected function processValue($value, bool $isRoot = false)
protected function processValue(mixed $value, bool $isRoot = false)
{
if (!$value instanceof Definition || $value->isAbstract() || $value->isSynthetic() || !$value->hasTag('container.service_subscriber')) {
return parent::processValue($value, $isRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function process(ContainerBuilder $container)
/**
* {@inheritdoc}
*/
protected function processValue($value, bool $isRoot = false)
protected function processValue(mixed $value, bool $isRoot = false)
{
if (!$value instanceof Reference) {
return parent::processValue($value, $isRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function process(ContainerBuilder $container)
/**
* {@inheritdoc}
*/
protected function processValue($value, bool $isRoot = false)
protected function processValue(mixed $value, bool $isRoot = false)
{
if ($value instanceof Reference && isset($this->replacements[$referenceId = (string) $value])) {
// Perform the replacement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function process(ContainerBuilder $container)
/**
* {@inheritdoc}
*/
protected function processValue($value, bool $isRoot = false)
protected function processValue(mixed $value, bool $isRoot = false)
{
if ($value instanceof TypedReference && $value->getType() === (string) $value) {
// Already checked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ResolveChildDefinitionsPass extends AbstractRecursivePass
{
private $currentPath;

protected function processValue($value, bool $isRoot = false)
protected function processValue(mixed $value, bool $isRoot = false)
{
if (!$value instanceof Definition) {
return parent::processValue($value, $isRoot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
class ResolveEnvPlaceholdersPass extends AbstractRecursivePass
{
protected function processValue($value, bool $isRoot = false)
protected function processValue(mixed $value, bool $isRoot = false)
{
if (\is_string($value)) {
return $this->container->resolveEnvPlaceholders($value, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ResolveFactoryClassPass extends AbstractRecursivePass
/**
* {@inheritdoc}
*/
protected function processValue($value, bool $isRoot = false)
protected function processValue(mixed $value, bool $isRoot = false)
{
if ($value instanceof Definition && \is_array($factory = $value->getFactory()) && null === $factory[0]) {
if (null === $class = $value->getClass()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function process(ContainerBuilder $container)
/**
* {@inheritdoc}
*/
protected function processValue($value, bool $isRoot = false)
protected function processValue(mixed $value, bool $isRoot = false)
{
if ($value instanceof ArgumentInterface) {
return $value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,9 @@ public function process(ContainerBuilder $container)
/**
* Processes arguments to determine invalid references.
*
* @return mixed
*
* @throws RuntimeException When an invalid reference is found
*/
private function processValue($value, int $rootLevel = 0, int $level = 0)
private function processValue(mixed $value, int $rootLevel = 0, int $level = 0): mixed
{
if ($value instanceof ServiceClosureArgument) {
$value->setValues($this->processValue($value->getValues(), 1, 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ResolveNamedArgumentsPass extends AbstractRecursivePass
/**
* {@inheritdoc}
*/
protected function processValue($value, bool $isRoot = false)
protected function processValue(mixed $value, bool $isRoot = false)
{
if ($value instanceof AbstractArgument && $value->getText().'.' === $value->getTextWithContext()) {
$value->setContext(sprintf('A value found in service "%s"', $this->currentId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function process(ContainerBuilder $container)
/**
* {@inheritdoc}
*/
protected function processValue($value, bool $isRoot = false)
protected function processValue(mixed $value, bool $isRoot = false)
{
if ($value instanceof Reference && ContainerBuilder::IGNORE_ON_UNINITIALIZED_REFERENCE !== $value->getInvalidBehavior() && $this->container->hasDefinition($id = (string) $value)) {
$definition = $this->container->getDefinition($id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@
class ResolveParameterPlaceHoldersPass extends AbstractRecursivePass
{
private $bag;
private $resolveArrays;
private $throwOnResolveException;

public function __construct($resolveArrays = true, $throwOnResolveException = true)
public function __construct(
private bool $resolveArrays = true,
private bool $throwOnResolveException = true,
)
{
$this->resolveArrays = $resolveArrays;
$this->throwOnResolveException = $throwOnResolveException;
}

/**
Expand Down Expand Up @@ -60,7 +59,7 @@ public function process(ContainerBuilder $container)
$this->bag = null;
}

protected function processValue($value, bool $isRoot = false)
protected function processValue(mixed $value, bool $isRoot = false)
{
if (\is_string($value)) {
try {
Expand Down
Loading