<commit_before><?php

declare(strict_types=1);

namespace Rector\SymfonyPhpConfig;

use Rector\Core\Exception\ShouldNotHappenException;
use Rector\SymfonyPhpConfig\Reflection\ArgumentAndParameterFactory;
use ReflectionClass;
use function Symfony\Component\DependencyInjection\Loader\Configurator\inline_service;
use Symfony\Component\DependencyInjection\Loader\Configurator\InlineServiceConfigurator;
use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator;
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
use Symfony\Component\DependencyInjection\Loader\Configurator\ServicesConfigurator;

function inline_single_object(object $object, ServicesConfigurator $servicesConfigurator): ReferenceConfigurator
{
    $reflectionClass = new ReflectionClass($object);

    $className = $reflectionClass->getName();
    $propertyValues = resolve_property_values($reflectionClass, $object);
    $argumentValues = resolve_argument_values($reflectionClass, $object);

    // create fake factory with private accessor, as properties are different
    // @see https://symfony.com/doc/current/service_container/factories.html#passing-arguments-to-the-factory-method
    $servicesConfigurator->set(ArgumentAndParameterFactory::class);

    $servicesConfigurator->set($className)
        ->factory([service(ArgumentAndParameterFactory::class), 'create'])
        ->args([$className, $argumentValues, $propertyValues]);

    return service($className);
}

function inline_value_object(object $object): InlineServiceConfigurator
{
    $reflectionClass = new ReflectionClass($object);

    $className = $reflectionClass->getName();
    $argumentValues = resolve_argument_values($reflectionClass, $object);

    return inline_service($className)->args($argumentValues);
}


/**
 * @param object[] $objects
 * @return InlineServiceConfigurator[]
 */
function inline_value_objects(array $objects): array
{
    $inlineServices = [];
    foreach ($objects as $object) {
        $inlineServices[] = inline_value_object($object);
    }

    return $inlineServices;
}<commit_msg>fix Symfony inline_function fallback (#4219)<commit_after><?php

declare(strict_types=1);

namespace Rector\SymfonyPhpConfig;

use Rector\Core\Exception\ShouldNotHappenException;
use Rector\SymfonyPhpConfig\Reflection\ArgumentAndParameterFactory;
use ReflectionClass;
use function Symfony\Component\DependencyInjection\Loader\Configurator\inline;
use function Symfony\Component\DependencyInjection\Loader\Configurator\inline_service;
use Symfony\Component\DependencyInjection\Loader\Configurator\InlineServiceConfigurator;
use Symfony\Component\DependencyInjection\Loader\Configurator\ReferenceConfigurator;
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
use Symfony\Component\DependencyInjection\Loader\Configurator\ServicesConfigurator;

function inline_single_object(object $object, ServicesConfigurator $servicesConfigurator): ReferenceConfigurator
{
    $reflectionClass = new ReflectionClass($object);

    $className = $reflectionClass->getName();
    $propertyValues = resolve_property_values($reflectionClass, $object);
    $argumentValues = resolve_argument_values($reflectionClass, $object);

    // create fake factory with private accessor, as properties are different
    // @see https://symfony.com/doc/current/service_container/factories.html#passing-arguments-to-the-factory-method
    $servicesConfigurator->set(ArgumentAndParameterFactory::class);

    $servicesConfigurator->set($className)
        ->factory([service(ArgumentAndParameterFactory::class), 'create'])
        ->args([$className, $argumentValues, $propertyValues]);

    return service($className);
}

function inline_value_object(object $object): InlineServiceConfigurator
{
    $reflectionClass = new ReflectionClass($object);

    $className = $reflectionClass->getName();
    $argumentValues = resolve_argument_values($reflectionClass, $object);

    // Symfony 5.1+
    if (function_exists('Symfony\Component\DependencyInjection\Loader\Configurator\inline_service')) {
        return inline_service($className)->args($argumentValues);
    }

    // Symfony 5.0-
    return inline($className)->args($argumentValues);
}

/**
 * @param object[] $objects
 * @return InlineServiceConfigurator[]
 */
function inline_value_objects(array $objects): array
{
    $inlineServices = [];
    foreach ($objects as $object) {
        $inlineServices[] = inline_value_object($object);
    }

    return $inlineServices;
}
{'fraction_non_alphanumeric': 0.10998457130262287, 'fraction_numerical': 0.002204099625303064, 'mean_word_length': 6.2492012779552715, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 18, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1881118', 'n_tokens_mistral': 1238, 'n_tokens_neox': 1218, 'n_words': 199}