Repository: symfony/symfony
File: src/Symfony/Component/DependencyInjection/Loader/Configurator/AbstractConfigurator.php (PHP)

Code before:
        if ($value instanceof self) {
            throw new InvalidArgumentException(\sprintf('"%s()" can be used only at the root of service configuration files.', $value::FACTORY));
        }

        switch (true) {
            case null === $value:
            case \is_scalar($value):
            case $value instanceof \UnitEnum:
                return $value;

            case $value instanceof ArgumentInterface:
            case $value instanceof Definition:
            case $value instanceof Expression:
            case $value instanceof Parameter:
            case $value instanceof AbstractArgument:
            case $value instanceof Reference:
                if ($allowServices) {
                    return $value;
                }
        }

        throw new InvalidArgumentException(\sprintf('Cannot use values of type "%s" in service configuration files.', get_debug_type($value)));
    }

    /**
     * Convert a named closure to dumpable callable.
     *
     * @throws InvalidArgumentException if the closure is anonymous or references a non-static method
     */
    final public static function processClosure(\Closure $closure): callable
    {
        $function = new \ReflectionFunction($closure);
        if ($function->isAnonymous()) {
            throw new InvalidArgumentException('Anonymous closure not supported. The closure must be created from a static method or a global function.');
        }

        // Convert global_function(...) closure into 'global_function'
        if (!$class = $function->getClosureCalledClass()) {
            return $function->name;
        }

        // Convert Class::method(...) closure into ['Class', 'method']
        if ($function->isStatic()) {
            return [$class->name, $function->name];
        }

        throw new InvalidArgumentException(\sprintf('The method "%s::%s(...)" is not static.', $class->name, $function->name));
    }
}


Review comment (suggestion):
```suggestion
     * Converts a named closure to dumpable callable.
```

Code after:
        if ($value instanceof self) {
            throw new InvalidArgumentException(\sprintf('"%s()" can be used only at the root of service configuration files.', $value::FACTORY));
        }

        switch (true) {
            case null === $value:
            case \is_scalar($value):
            case $value instanceof \UnitEnum:
                return $value;

            case $value instanceof ArgumentInterface:
            case $value instanceof Definition:
            case $value instanceof Expression:
            case $value instanceof Parameter:
            case $value instanceof AbstractArgument:
            case $value instanceof Reference:
                if ($allowServices) {
                    return $value;
                }
        }

        throw new InvalidArgumentException(\sprintf('Cannot use values of type "%s" in service configuration files.', get_debug_type($value)));
    }

    /**
     * Converts a named closure to dumpable callable.
     *
     * @throws InvalidArgumentException if the closure is anonymous or references a non-static method
     */
    final public static function processClosure(\Closure $closure): callable
    {
        $function = new \ReflectionFunction($closure);
        if ($function->isAnonymous()) {
            throw new InvalidArgumentException('Anonymous closure not supported. The closure must be created from a static method or a global function.');
        }

        // Convert global_function(...) closure into 'global_function'
        if (!$class = $function->getClosureCalledClass()) {
            return $function->name;
        }

        // Convert Class::method(...) closure into ['Class', 'method']
        if ($function->isStatic()) {
            return [$class->name, $function->name];
        }

        throw new InvalidArgumentException(\sprintf('The method "%s::%s(...)" is not static.', $class->name, $function->name));
    }
}