<commit_before><?php

namespace Emonkak\Di\ServiceProvider;

use Emonkak\Di\Container;
use Emonkak\Di\Injection\MethodInjection;
use Emonkak\Di\Injection\PropertyInjection;
use Emonkak\Di\Value\InjectableValueInterface;
use Emonkak\Di\Value\InjectableValueVisitorInterface;
use Emonkak\Di\Value\ObjectValueInterface;
use Emonkak\Di\Value\ProviderValue;
use Emonkak\Di\Value\SingletonValue;

class ServiceProviderGenerator implements InjectableValueVisitorInterface
{
    private $container;

    private $definitions = [];

    /**
     * @param Container $container
     */
    public function __construct(Container $container)
    {
        $this->container = $container;
    }

    /**
     * {@inheritDoc}
     */
    public function visitValue(InjectableValueInterface $value)
    {
        return $this->container->getKey($value);
    }

    /**
     * {@inheritDoc}
     */
    public function visitObjectValue(ObjectValueInterface $value)
    {
        $methodCalls = [];
        $propertySetters = [];

        foreach ($value->getMethodInjections() as $methodInjection) {
            $methodCalls[] = $this->dumpMethodCall($methodInjection);
        }

        foreach ($value->getPropertyInjections() as $properyInjection) {
            $propertySetters[] = $this->dumpPropertySet($properyInjection);
        }

        $procedures = implode("\n", array_merge(
            [$this->dumpNewInstance($value)],
            $methodCalls,
            $propertySetters,
            [$this->dumpReturn()]
        ));

            $factory = <<<EOL
function(\$c) {
$procedures
        }
EOL;

        if (count($propertySetters) > 0) {
            $className = $value->getClass()->getName();
            $factory = 'Closure::bind(' . $factory . ", \$this, '$className')";
        }

        if (!($value instanceof SingletonValue)) {
            $factory = '$c->factory(' . $factory . ')';
        }

        $key = $this->container->getKey($value);
        $this->definitions[$key] = <<<EOL
        \$c['$key'] = $factory;
EOL;

        return $key;
    }

    /**
     * @param string $className
     * @param string $namespace
     * @return string
     */<commit_msg>ServiceProviderGenerator: Remove private property injection<commit_after><?php

namespace Emonkak\Di\ServiceProvider;

use Emonkak\Di\Container;
use Emonkak\Di\Injection\MethodInjection;
use Emonkak\Di\Injection\PropertyInjection;
use Emonkak\Di\Value\InjectableValueInterface;
use Emonkak\Di\Value\InjectableValueVisitorInterface;
use Emonkak\Di\Value\ObjectValueInterface;
use Emonkak\Di\Value\ProviderValue;
use Emonkak\Di\Value\SingletonValue;

class ServiceProviderGenerator implements InjectableValueVisitorInterface
{
    private $container;

    private $definitions = [];

    /**
     * @param Container $container
     */
    public function __construct(Container $container)
    {
        $this->container = $container;
    }

    /**
     * {@inheritDoc}
     */
    public function visitValue(InjectableValueInterface $value)
    {
        return $this->container->getKey($value);
    }

    /**
     * {@inheritDoc}
     */
    public function visitObjectValue(ObjectValueInterface $value)
    {
        $methodCalls = [];
        $propertySetters = [];

        foreach ($value->getMethodInjections() as $methodInjection) {
            $methodCalls[] = $this->dumpMethodCall($methodInjection);
        }

        foreach ($value->getPropertyInjections() as $properyInjection) {
            $propertySetters[] = $this->dumpPropertySet($properyInjection);
        }

        $procedures = implode("\n", array_merge(
            [$this->dumpNewInstance($value)],
            $methodCalls,
            $propertySetters,
            [$this->dumpReturn()]
        ));

            $factory = <<<EOL
function(\$c) {
$procedures
        }
EOL;

        if (!($value instanceof SingletonValue)) {
            $factory = '$c->factory(' . $factory . ')';
        }

        $key = $this->container->getKey($value);
        $this->definitions[$key] = <<<EOL
        \$c['$key'] = $factory;
EOL;

        return $key;
    }

    /**
     * @param string $className
     * @param string $namespace
     * @return string
     */
{'fraction_non_alphanumeric': 0.13802950975725845, 'fraction_numerical': 0.00023798191337458352, 'mean_word_length': 2.5770212765957448, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 32, 'https://': 0, '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': '3131350', 'n_tokens_mistral': 1256, 'n_tokens_neox': 1232, 'n_words': 210}