<commit_before><?php

namespace Emonkak\Di;

use Emonkak\Di\InjectionPolicy\InjectionPolicyInterface;
use Emonkak\Di\Injection\MethodInjection;
use Emonkak\Di\Injection\ParameterInjection;
use Emonkak\Di\Injection\PropertyInjection;
use Emonkak\Di\ValueResolver\ValueResolverInterface;

class InjectionFinder
{
    private $valueResolver;
    private $injectionPolicy;

    /**
     * @param ValueResolverInterface   $valueResolver
     * @param InjectionPolicyInterface $injectionPolicy
     */
    public function __construct(
        ValueResolverInterface $valueResolver,
        InjectionPolicyInterface $injectionPolicy
    ) {
        $this->valueResolver = $valueResolver;
        $this->injectionPolicy = $injectionPolicy;
    }

    /**
     * @param \ReflectionClass $class
     * @return MethodInjection|null
     */
    public function getConstructorInjection(\ReflectionClass $class)
    {
        $constructor = $class->getConstructor();
        return $constructor ? $this->createMethodInjection($constructor) : null;
    }

    /**
     * @param \ReflectionClass $class
     * @return MethodInjection[]
     */
    public function getMethodInjections(\ReflectionClass $class)
    {
        $injections = [];

        $methods = $this->injectionPolicy->getInjectableMethods($class);
        foreach ($methods as $method) {
            $injections[] = $this->createMethodInjection($method);
        }

        return $injections;
    }

    /**
     * @param \ReflectionClass $class
     * @return PropertyInjection[]
     */
    public function getPropertyInjections(\ReflectionClass $class)
    {
        $injections = [];

        $properties = $this->injectionPolicy->getInjectableProperties($class);
        foreach ($properties as $property) {
            $injections[] = $this->createPropertyInjection($property);
        }

        return $injections;
    }

    /**
     * @param \ReflectionFunctionAbstract $function
     * @return InjectableValueInterface
     */
    public function getParameters(\ReflectionFunctionAbstract $function)
    {
        $params = [];
        foreach ($function->getParameters() as $param) {
            $value = $this->valueResolver->getParameterValue($param);
            if ($value === null) {
                throw new \LogicException(sprintf(
                    'Parameter "$%s" of "%s::%s()" can not be resolved.',
                    $param->getName(),
                    $method->getDeclaringClass()->getName(),
                    $method->getName()
                ));
            }
            $params[] = $value;
        }
        return $params;
    }

    /**
     * @param \ReflectionMethod $mehtod
     * @return MethodInjection
     */
    private function createMethodInjection(\ReflectionMethod $method)
    {
        $params = $this->getParameters($method);
        return new MethodInjection($method->getName(), $params);
    }

    /**
     * @param \ReflectionMethod $mehtod
     * @return PropertyInjection
     */
    private function createPropertyInjection(\ReflectionProperty $property)
    {
        $value = $this->valueResolver->getPropertyValue($property);
        if ($value === null) {
            throw new \LogicException(sprintf(
                'Property "%s::$%s" can not be resolved.',
                $property->getDeclaringClass()->getName(),
                $property->getName()
            ));
        }
        return new PropertyInjection($property->getName(), $value);
    }
}
<commit_msg>Fix undefinied variable<commit_after><?php

namespace Emonkak\Di;

use Emonkak\Di\InjectionPolicy\InjectionPolicyInterface;
use Emonkak\Di\Injection\MethodInjection;
use Emonkak\Di\Injection\ParameterInjection;
use Emonkak\Di\Injection\PropertyInjection;
use Emonkak\Di\ValueResolver\ValueResolverInterface;

class InjectionFinder
{
    private $valueResolver;
    private $injectionPolicy;

    /**
     * @param ValueResolverInterface   $valueResolver
     * @param InjectionPolicyInterface $injectionPolicy
     */
    public function __construct(
        ValueResolverInterface $valueResolver,
        InjectionPolicyInterface $injectionPolicy
    ) {
        $this->valueResolver = $valueResolver;
        $this->injectionPolicy = $injectionPolicy;
    }

    /**
     * @param \ReflectionClass $class
     * @return MethodInjection|null
     */
    public function getConstructorInjection(\ReflectionClass $class)
    {
        $constructor = $class->getConstructor();
        return $constructor ? $this->createMethodInjection($constructor) : null;
    }

    /**
     * @param \ReflectionClass $class
     * @return MethodInjection[]
     */
    public function getMethodInjections(\ReflectionClass $class)
    {
        $injections = [];

        $methods = $this->injectionPolicy->getInjectableMethods($class);
        foreach ($methods as $method) {
            $injections[] = $this->createMethodInjection($method);
        }

        return $injections;
    }

    /**
     * @param \ReflectionClass $class
     * @return PropertyInjection[]
     */
    public function getPropertyInjections(\ReflectionClass $class)
    {
        $injections = [];

        $properties = $this->injectionPolicy->getInjectableProperties($class);
        foreach ($properties as $property) {
            $injections[] = $this->createPropertyInjection($property);
        }

        return $injections;
    }

    /**
     * @param \ReflectionFunctionAbstract $function
     * @return InjectableValueInterface
     */
    public function getParameters(\ReflectionFunctionAbstract $function)
    {
        $params = [];
        foreach ($function->getParameters() as $param) {
            $value = $this->valueResolver->getParameterValue($param);
            if ($value === null) {
                throw new \LogicException(sprintf(
                    'Parameter "$%s" of "%s()" can not be resolved.',
                    $param->getName(),
                    $function->getName()
                ));
            }
            $params[] = $value;
        }
        return $params;
    }

    /**
     * @param \ReflectionMethod $mehtod
     * @return MethodInjection
     */
    private function createMethodInjection(\ReflectionMethod $method)
    {
        $params = $this->getParameters($method);
        return new MethodInjection($method->getName(), $params);
    }

    /**
     * @param \ReflectionMethod $mehtod
     * @return PropertyInjection
     */
    private function createPropertyInjection(\ReflectionProperty $property)
    {
        $value = $this->valueResolver->getPropertyValue($property);
        if ($value === null) {
            throw new \LogicException(sprintf(
                'Property "%s::$%s" can not be resolved.',
                $property->getDeclaringClass()->getName(),
                $property->getName()
            ));
        }
        return new PropertyInjection($property->getName(), $value);
    }
}

{'fraction_non_alphanumeric': 0.1201153568853641, 'fraction_numerical': 0.0, 'mean_word_length': 2.4133858267716537, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, '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': '2608040', 'n_tokens_mistral': 1818, 'n_tokens_neox': 1779, 'n_words': 345}