[DependencyInjection] Added type-hints on compiler passes.
This commit is contained in:
parent
a25848b2b5
commit
d5bc28ad20
@ -68,11 +68,10 @@ abstract class AbstractRecursivePass implements CompilerPassInterface
|
||||
* Processes a value found in a definition tree.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param bool $isRoot
|
||||
*
|
||||
* @return mixed The processed value
|
||||
*/
|
||||
protected function processValue($value, $isRoot = false)
|
||||
protected function processValue($value, bool $isRoot = false)
|
||||
{
|
||||
if (\is_array($value)) {
|
||||
foreach ($value as $k => $v) {
|
||||
@ -105,14 +104,11 @@ abstract class AbstractRecursivePass implements CompilerPassInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Definition $definition
|
||||
* @param bool $required
|
||||
*
|
||||
* @return \ReflectionFunctionAbstract|null
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
protected function getConstructor(Definition $definition, $required)
|
||||
protected function getConstructor(Definition $definition, bool $required)
|
||||
{
|
||||
if (\is_string($factory = $definition->getFactory())) {
|
||||
if (!\function_exists($factory)) {
|
||||
@ -161,14 +157,11 @@ abstract class AbstractRecursivePass implements CompilerPassInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Definition $definition
|
||||
* @param string $method
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*
|
||||
* @return \ReflectionFunctionAbstract
|
||||
*/
|
||||
protected function getReflectionMethod(Definition $definition, $method)
|
||||
protected function getReflectionMethod(Definition $definition, string $method)
|
||||
{
|
||||
if ('__construct' === $method) {
|
||||
return $this->getConstructor($definition, true);
|
||||
|
@ -74,7 +74,7 @@ class AnalyzeServiceReferencesPass extends AbstractRecursivePass
|
||||
}
|
||||
}
|
||||
|
||||
protected function processValue($value, $isRoot = false)
|
||||
protected function processValue($value, bool $isRoot = false)
|
||||
{
|
||||
$lazy = $this->lazy;
|
||||
$inExpression = $this->inExpression();
|
||||
|
@ -65,7 +65,7 @@ class AutowirePass extends AbstractRecursivePass
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function processValue($value, $isRoot = false)
|
||||
protected function processValue($value, bool $isRoot = false)
|
||||
{
|
||||
try {
|
||||
return $this->doProcessValue($value, $isRoot);
|
||||
@ -80,7 +80,7 @@ class AutowirePass extends AbstractRecursivePass
|
||||
}
|
||||
}
|
||||
|
||||
private function doProcessValue($value, $isRoot = false)
|
||||
private function doProcessValue($value, bool $isRoot = false)
|
||||
{
|
||||
if ($value instanceof TypedReference) {
|
||||
if ($ref = $this->getAutowiredReference($value)) {
|
||||
@ -373,7 +373,7 @@ class AutowirePass extends AbstractRecursivePass
|
||||
$this->ambiguousServiceTypes[$type][] = $id;
|
||||
}
|
||||
|
||||
private function createTypeNotFoundMessageCallback(TypedReference $reference, $label)
|
||||
private function createTypeNotFoundMessageCallback(TypedReference $reference, string $label)
|
||||
{
|
||||
$container = new ContainerBuilder($this->container->getParameterBag());
|
||||
$container->setAliases($this->container->getAliases());
|
||||
@ -386,7 +386,7 @@ class AutowirePass extends AbstractRecursivePass
|
||||
};
|
||||
}
|
||||
|
||||
private function createTypeNotFoundMessage(ContainerBuilder $container, TypedReference $reference, $label, string $currentId)
|
||||
private function createTypeNotFoundMessage(ContainerBuilder $container, TypedReference $reference, string $label, string $currentId)
|
||||
{
|
||||
if (!$r = $container->getReflectionClass($type = $reference->getType(), false)) {
|
||||
// either $type does not exist or a parent class does not exist
|
||||
@ -444,7 +444,7 @@ class AutowirePass extends AbstractRecursivePass
|
||||
return sprintf(' You should maybe alias this %s to %s.', class_exists($type, false) ? 'class' : 'interface', $message);
|
||||
}
|
||||
|
||||
private function getAliasesSuggestionForType(ContainerBuilder $container, $type, $extraContext = null)
|
||||
private function getAliasesSuggestionForType(ContainerBuilder $container, string $type, $extraContext = null)
|
||||
{
|
||||
$aliases = [];
|
||||
foreach (class_parents($type) + class_implements($type) as $parent) {
|
||||
|
@ -23,7 +23,7 @@ class AutowireRequiredMethodsPass extends AbstractRecursivePass
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function processValue($value, $isRoot = false)
|
||||
protected function processValue($value, bool $isRoot = false)
|
||||
{
|
||||
$value = parent::processValue($value, $isRoot);
|
||||
|
||||
|
@ -32,7 +32,7 @@ class CheckArgumentsValidityPass extends AbstractRecursivePass
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function processValue($value, $isRoot = false)
|
||||
protected function processValue($value, bool $isRoot = false)
|
||||
{
|
||||
if (!$value instanceof Definition) {
|
||||
return parent::processValue($value, $isRoot);
|
||||
|
@ -43,7 +43,7 @@ class CheckExceptionOnInvalidReferenceBehaviorPass extends AbstractRecursivePass
|
||||
}
|
||||
}
|
||||
|
||||
protected function processValue($value, $isRoot = false)
|
||||
protected function processValue($value, bool $isRoot = false)
|
||||
{
|
||||
if (!$value instanceof Reference) {
|
||||
return parent::processValue($value, $isRoot);
|
||||
|
@ -25,7 +25,7 @@ use Symfony\Component\DependencyInjection\Reference;
|
||||
*/
|
||||
class CheckReferenceValidityPass extends AbstractRecursivePass
|
||||
{
|
||||
protected function processValue($value, $isRoot = false)
|
||||
protected function processValue($value, bool $isRoot = false)
|
||||
{
|
||||
if ($isRoot && $value instanceof Definition && ($value->isSynthetic() || $value->isAbstract())) {
|
||||
return $value;
|
||||
|
@ -53,12 +53,8 @@ class Compiler
|
||||
|
||||
/**
|
||||
* Adds a pass to the PassConfig.
|
||||
*
|
||||
* @param CompilerPassInterface $pass A compiler pass
|
||||
* @param string $type The type of the pass
|
||||
* @param int $priority Used to sort the passes
|
||||
*/
|
||||
public function addPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION, int $priority = 0)
|
||||
public function addPass(CompilerPassInterface $pass, string $type = PassConfig::TYPE_BEFORE_OPTIMIZATION, int $priority = 0)
|
||||
{
|
||||
$this->passConfig->addPass($pass, $type, $priority);
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ class DefinitionErrorExceptionPass extends AbstractRecursivePass
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function processValue($value, $isRoot = false)
|
||||
protected function processValue($value, bool $isRoot = false)
|
||||
{
|
||||
if (!$value instanceof Definition || !$value->hasErrors()) {
|
||||
return parent::processValue($value, $isRoot);
|
||||
|
@ -101,7 +101,7 @@ class InlineServiceDefinitionsPass extends AbstractRecursivePass
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function processValue($value, $isRoot = false)
|
||||
protected function processValue($value, bool $isRoot = false)
|
||||
{
|
||||
if ($value instanceof ArgumentInterface) {
|
||||
// Reference found in ArgumentInterface::getValues() are not inlineable
|
||||
@ -155,7 +155,7 @@ class InlineServiceDefinitionsPass extends AbstractRecursivePass
|
||||
*
|
||||
* @return bool If the definition is inlineable
|
||||
*/
|
||||
private function isInlineableDefinition($id, Definition $definition)
|
||||
private function isInlineableDefinition(string $id, Definition $definition)
|
||||
{
|
||||
if ($definition->hasErrors() || $definition->isDeprecated() || $definition->isLazy() || $definition->isSynthetic()) {
|
||||
return false;
|
||||
|
@ -110,13 +110,9 @@ class PassConfig
|
||||
/**
|
||||
* Adds a pass.
|
||||
*
|
||||
* @param CompilerPassInterface $pass A Compiler pass
|
||||
* @param string $type The pass type
|
||||
* @param int $priority Used to sort the passes
|
||||
*
|
||||
* @throws InvalidArgumentException when a pass type doesn't exist
|
||||
*/
|
||||
public function addPass(CompilerPassInterface $pass, $type = self::TYPE_BEFORE_OPTIMIZATION, int $priority = 0)
|
||||
public function addPass(CompilerPassInterface $pass, string $type = self::TYPE_BEFORE_OPTIMIZATION, int $priority = 0)
|
||||
{
|
||||
$property = $type.'Passes';
|
||||
if (!isset($this->$property)) {
|
||||
|
@ -60,7 +60,7 @@ class RegisterEnvVarProcessorsPass implements CompilerPassInterface
|
||||
}
|
||||
}
|
||||
|
||||
private static function validateProvidedTypes($types, $class)
|
||||
private static function validateProvidedTypes(string $types, string $class)
|
||||
{
|
||||
$types = explode('|', $types);
|
||||
|
||||
|
@ -25,7 +25,7 @@ use Symfony\Contracts\Service\ServiceSubscriberInterface;
|
||||
*/
|
||||
class RegisterServiceSubscribersPass extends AbstractRecursivePass
|
||||
{
|
||||
protected function processValue($value, $isRoot = false)
|
||||
protected function processValue($value, bool $isRoot = false)
|
||||
{
|
||||
if (!$value instanceof Definition || $value->isAbstract() || $value->isSynthetic() || !$value->hasTag('container.service_subscriber')) {
|
||||
return parent::processValue($value, $isRoot);
|
||||
|
@ -75,7 +75,7 @@ class RemoveUnusedDefinitionsPass extends AbstractRecursivePass
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function processValue($value, $isRoot = false)
|
||||
protected function processValue($value, bool $isRoot = false)
|
||||
{
|
||||
if (!$value instanceof Reference) {
|
||||
return parent::processValue($value, $isRoot);
|
||||
|
@ -80,7 +80,7 @@ class ReplaceAliasByActualDefinitionPass extends AbstractRecursivePass
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function processValue($value, $isRoot = false)
|
||||
protected function processValue($value, bool $isRoot = false)
|
||||
{
|
||||
if ($value instanceof Reference && isset($this->replacements[$referenceId = (string) $value])) {
|
||||
// Perform the replacement
|
||||
|
@ -90,7 +90,7 @@ class ResolveBindingsPass extends AbstractRecursivePass
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function processValue($value, $isRoot = false)
|
||||
protected function processValue($value, bool $isRoot = false)
|
||||
{
|
||||
if ($value instanceof TypedReference && $value->getType() === (string) $value) {
|
||||
// Already checked
|
||||
|
@ -28,7 +28,7 @@ class ResolveChildDefinitionsPass extends AbstractRecursivePass
|
||||
{
|
||||
private $currentPath;
|
||||
|
||||
protected function processValue($value, $isRoot = false)
|
||||
protected function processValue($value, bool $isRoot = false)
|
||||
{
|
||||
if (!$value instanceof Definition) {
|
||||
return parent::processValue($value, $isRoot);
|
||||
|
@ -18,7 +18,7 @@ use Symfony\Component\DependencyInjection\Definition;
|
||||
*/
|
||||
class ResolveEnvPlaceholdersPass extends AbstractRecursivePass
|
||||
{
|
||||
protected function processValue($value, $isRoot = false)
|
||||
protected function processValue($value, bool $isRoot = false)
|
||||
{
|
||||
if (\is_string($value)) {
|
||||
return $this->container->resolveEnvPlaceholders($value, true);
|
||||
|
@ -22,7 +22,7 @@ class ResolveFactoryClassPass extends AbstractRecursivePass
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function processValue($value, $isRoot = false)
|
||||
protected function processValue($value, bool $isRoot = false)
|
||||
{
|
||||
if ($value instanceof Definition && \is_array($factory = $value->getFactory()) && null === $factory[0]) {
|
||||
if (null === $class = $value->getClass()) {
|
||||
|
@ -47,7 +47,7 @@ class ResolveHotPathPass extends AbstractRecursivePass
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function processValue($value, $isRoot = false)
|
||||
protected function processValue($value, bool $isRoot = false)
|
||||
{
|
||||
if ($value instanceof ArgumentInterface) {
|
||||
return $value;
|
||||
|
@ -44,7 +44,7 @@ class ResolveInstanceofConditionalsPass implements CompilerPassInterface
|
||||
}
|
||||
}
|
||||
|
||||
private function processDefinition(ContainerBuilder $container, $id, Definition $definition)
|
||||
private function processDefinition(ContainerBuilder $container, string $id, Definition $definition)
|
||||
{
|
||||
$instanceofConditionals = $definition->getInstanceofConditionals();
|
||||
$autoconfiguredInstanceof = $definition->isAutoconfigured() ? $container->getAutoconfiguredInstanceof() : [];
|
||||
|
@ -53,7 +53,7 @@ class ResolveInvalidReferencesPass implements CompilerPassInterface
|
||||
*
|
||||
* @throws RuntimeException When an invalid reference is found
|
||||
*/
|
||||
private function processValue($value, $rootLevel = 0, $level = 0)
|
||||
private function processValue($value, int $rootLevel = 0, int $level = 0)
|
||||
{
|
||||
if ($value instanceof ServiceClosureArgument) {
|
||||
$value->setValues($this->processValue($value->getValues(), 1, 1));
|
||||
|
@ -26,7 +26,7 @@ class ResolveNamedArgumentsPass extends AbstractRecursivePass
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function processValue($value, $isRoot = false)
|
||||
protected function processValue($value, bool $isRoot = false)
|
||||
{
|
||||
if (!$value instanceof Definition) {
|
||||
return parent::processValue($value, $isRoot);
|
||||
|
@ -58,7 +58,7 @@ class ResolveParameterPlaceHoldersPass extends AbstractRecursivePass
|
||||
$this->bag = null;
|
||||
}
|
||||
|
||||
protected function processValue($value, $isRoot = false)
|
||||
protected function processValue($value, bool $isRoot = false)
|
||||
{
|
||||
if (\is_string($value)) {
|
||||
$v = $this->bag->resolveValue($value);
|
||||
|
@ -42,7 +42,7 @@ class ResolveReferencesToAliasesPass extends AbstractRecursivePass
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function processValue($value, $isRoot = false)
|
||||
protected function processValue($value, bool $isRoot = false)
|
||||
{
|
||||
if (!$value instanceof Reference) {
|
||||
return parent::processValue($value, $isRoot);
|
||||
|
@ -25,7 +25,7 @@ class ResolveServiceSubscribersPass extends AbstractRecursivePass
|
||||
{
|
||||
private $serviceLocator;
|
||||
|
||||
protected function processValue($value, $isRoot = false)
|
||||
protected function processValue($value, bool $isRoot = false)
|
||||
{
|
||||
if ($value instanceof Reference && $this->serviceLocator && \in_array((string) $value, [ContainerInterface::class, ServiceProviderInterface::class], true)) {
|
||||
return new Reference($this->serviceLocator);
|
||||
|
@ -25,7 +25,7 @@ class ResolveTaggedIteratorArgumentPass extends AbstractRecursivePass
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function processValue($value, $isRoot = false)
|
||||
protected function processValue($value, bool $isRoot = false)
|
||||
{
|
||||
if (!$value instanceof TaggedIteratorArgument) {
|
||||
return parent::processValue($value, $isRoot);
|
||||
|
@ -29,7 +29,7 @@ final class ServiceLocatorTagPass extends AbstractRecursivePass
|
||||
{
|
||||
use PriorityTaggedServiceTrait;
|
||||
|
||||
protected function processValue($value, $isRoot = false)
|
||||
protected function processValue($value, bool $isRoot = false)
|
||||
{
|
||||
if ($value instanceof ServiceLocatorArgument) {
|
||||
if ($value->getTaggedIteratorArgument()) {
|
||||
@ -87,11 +87,9 @@ final class ServiceLocatorTagPass extends AbstractRecursivePass
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContainerBuilder $container
|
||||
* @param Reference[] $refMap
|
||||
* @param string|null $callerId
|
||||
*/
|
||||
public static function register(ContainerBuilder $container, array $refMap, $callerId = null): Reference
|
||||
public static function register(ContainerBuilder $container, array $refMap, string $callerId = null): Reference
|
||||
{
|
||||
foreach ($refMap as $id => $ref) {
|
||||
if (!$ref instanceof Reference) {
|
||||
|
Reference in New Issue
Block a user