Repository: symfony/symfony
File: src/Symfony/Component/DependencyInjection/Compiler/AutowireAsDecoratorPass.php (PHP)

Code before:
{
    public function process(ContainerBuilder $container): void
    {
        foreach ($container->getDefinitions() as $id => $definition) {
            if ($this->accept($definition) && $reflectionClass = $container->getReflectionClass($definition->getClass(), false)) {
                $this->processClass($id, $container, $definition, $reflectionClass);
            }
        }
    }

    private function accept(Definition $definition): bool
    {
        return !$definition->hasTag('container.ignore_attributes') && $definition->isAutowired();
    }

    private function processClass(string $id, ContainerBuilder $container, Definition $definition, \ReflectionClass $reflectionClass): void
    {
        $decoratorAttributes = $reflectionClass->getAttributes(AsDecorator::class, \ReflectionAttribute::IS_INSTANCEOF);
        $tagDecoratorAttributes = $reflectionClass->getAttributes(AsTagDecorator::class, \ReflectionAttribute::IS_INSTANCEOF);

        if (!$decoratorAttributes && !$tagDecoratorAttributes) {
            return;
        }

        if ($decoratorAttributes) {
            if (1 === \count($decoratorAttributes) && !$tagDecoratorAttributes) {
                $attribute = $decoratorAttributes[0]->newInstance();
                $definition->setDecoratedService($attribute->decorates, null, $attribute->priority, $attribute->onInvalid);

                return;
            }

            foreach ($decoratorAttributes as $attribute) {
                $attribute = $attribute->newInstance();

                $clonedDefinition = clone $definition;
                $clonedDefinition->setDecoratedService($attribute->decorates, null, $attribute->priority, $attribute->onInvalid);
                $container->setDefinition(\sprintf('.decorator.%s.%s', $attribute->decorates, $id), $clonedDefinition);
            }
        }

        if ($tagDecoratorAttributes) {
            foreach ($tagDecoratorAttributes as $attribute) {
                $attribute = $attribute->newInstance();

                $clonedDefinition = clone $definition;
                $tagAttributes = [
                    'decorates_tag' => $attribute->tag,
                    'priority' => $attribute->priority,
                ];


Review comment (suggestion):
no need to nest the next if nor the next foreach:
```suggestion
        if (1 === \count($decoratorAttributes) && !$tagDecoratorAttributes) {
```

Code after:
{
    public function process(ContainerBuilder $container): void
    {
        foreach ($container->getDefinitions() as $id => $definition) {
            if ($this->accept($definition) && $reflectionClass = $container->getReflectionClass($definition->getClass(), false)) {
                $this->processClass($id, $container, $definition, $reflectionClass);
            }
        }
    }

    private function accept(Definition $definition): bool
    {
        return !$definition->hasTag('container.ignore_attributes') && $definition->isAutowired();
    }

    private function processClass(string $id, ContainerBuilder $container, Definition $definition, \ReflectionClass $reflectionClass): void
    {
        $decoratorAttributes = $reflectionClass->getAttributes(AsDecorator::class, \ReflectionAttribute::IS_INSTANCEOF);
        $tagDecoratorAttributes = $reflectionClass->getAttributes(AsTagDecorator::class, \ReflectionAttribute::IS_INSTANCEOF);

        if (!$decoratorAttributes && !$tagDecoratorAttributes) {
            return;
        }

        if (1 === \count($decoratorAttributes) && !$tagDecoratorAttributes) {
            $attribute = $decoratorAttributes[0]->newInstance();
            $definition->setDecoratedService($attribute->decorates, null, $attribute->priority, $attribute->onInvalid);

            return;
        }

        foreach ($decoratorAttributes as $attribute) {
            $attribute = $attribute->newInstance();

            $clonedDefinition = clone $definition;
            $clonedDefinition->setDecoratedService($attribute->decorates, null, $attribute->priority, $attribute->onInvalid);
            $container->setDefinition(\sprintf('.decorator.%s.%s', $attribute->decorates, $id), $clonedDefinition);
        }

        foreach ($tagDecoratorAttributes as $attribute) {
            $attribute = $attribute->newInstance();

            $clonedDefinition = clone $definition;
            $tagAttributes = [
                'decorates_tag' => $attribute->tag,
                'priority' => $attribute->priority,
            ];

            if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $attribute->onInvalid) {
                $tagAttributes['on_invalid'] = $attribute->onInvalid;
            }