<commit_before><?php
/**
 * This file is part of the Everon components.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Everon\Component\Factory\Dependency;

use Everon\Component\Collection\Collection;
use Everon\Component\Collection\CollectionInterface;
use Everon\Component\Factory\Exception\DependencyCannotInjectItselfException;
use Everon\Component\Factory\Exception\DependencyServiceAlreadyRegisteredException;
use Everon\Component\Factory\Exception\InstanceIsNotObjectException;
use Everon\Component\Factory\Exception\UndefinedContainerDependencyException;
use Everon\Component\Factory\Exception\UndefinedDependencySetterException;
use Everon\Component\Utils\Text\EndsWith;
use Everon\Component\Utils\Text\LastTokenToName;

class Container implements ContainerInterface
{

    use EndsWith;
    use LastTokenToName;

    const DEPENDENCY_SETTER_FACTORY = 'Dependency\Setter\Factory';
    const TYPE_SETTER_INJECTION = 'Dependency\Setter';

    /**
     * @var CollectionInterface
     */
    protected $ServiceDefinitionCollection;

    /**
     * @var CollectionInterface
     */
    protected $ServiceCollection;

    /**
     * @var CollectionInterface
     */
    protected $ClassDependencyCollection;

    /**
     * @var CollectionInterface
     */
    protected $RequireFactoryCollection;

    /**
     * @var CollectionInterface
     */
    protected $InjectedCollection;

    /**
     * @param $setterName
     * @param $Receiver
     *
     * @throws UndefinedContainerDependencyException
     * @throws UndefinedDependencySetterException
     */
    protected function injectSetterDependency($setterName, $Receiver)
    {
        $receiverClassName = get_class($Receiver);
        $method = 'set' . $setterName; //eg. setConfigManager
        if (method_exists($Receiver, $method) === false) {
            throw new UndefinedDependencySetterException([
                $method,
                $setterName,
                $receiverClassName,
            ]);
        }

        $Dependency = $this->resolve($setterName);
        $Receiver->$method($Dependency);

        $this->getInjectedCollection()->set($receiverClassName, true);
    }

    /**
     * @param $className
     * @param bool $autoload
     *
     * @return array
     */
    protected function getClassSetterDependencies($className, $autoload = true)
    {
        if ($this->getClassDependencyCollection()->has($className)) {
            return $this->getClassDependencyCollection()->get($className);
        }

        $traits = class_uses($className, $autoload);
        $parents = class_parents($className, $autoload);

        foreach ($parents as $parent) {
            $traits = array_merge(
                class_uses($parent, $autoload),
                $traits
            );
        }

        $dependencies = array_keys($traits);
        $dependencies = array_filter($dependencies, function($dependencyName){
            return $this->isSetterInjection($dependencyName);
        }, \ARRAY_FILTER_USE_BOTH);

        $this->getClassDependencyCollection()->set($className, $dependencies);

        return $this->getClassDependencyCollection()->get($className);
    }

    /**<commit_msg>cleanups<commit_after><?php
/**
 * This file is part of the Everon components.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Everon\Component\Factory\Dependency;

use Everon\Component\Collection\Collection;
use Everon\Component\Collection\CollectionInterface;
use Everon\Component\Factory\Exception\DependencyCannotInjectItselfException;
use Everon\Component\Factory\Exception\DependencyServiceAlreadyRegisteredException;
use Everon\Component\Factory\Exception\InstanceIsNotObjectException;
use Everon\Component\Factory\Exception\UndefinedContainerDependencyException;
use Everon\Component\Factory\Exception\UndefinedDependencySetterException;
use Everon\Component\Utils\Text\EndsWith;
use Everon\Component\Utils\Text\LastTokenToName;

class Container implements ContainerInterface
{

    use EndsWith;
    use LastTokenToName;

    const DEPENDENCY_SETTER_FACTORY = 'Dependency\Setter\Factory';
    const TYPE_SETTER_INJECTION = 'Dependency\Setter';

    /**
     * @var CollectionInterface
     */
    protected $ServiceDefinitionCollection;

    /**
     * @var CollectionInterface
     */
    protected $ServiceCollection;

    /**
     * @var CollectionInterface
     */
    protected $ClassDependencyCollection;

    /**
     * @var CollectionInterface
     */
    protected $RequireFactoryCollection;

    /**
     * @var CollectionInterface
     */
    protected $InjectedCollection;

    /**
     * @param $setterName
     * @param $Receiver
     *
     * @throws UndefinedContainerDependencyException
     * @throws UndefinedDependencySetterException
     */
    protected function injectSetterDependency($setterName, $Receiver)
    {
        $receiverClassName = get_class($Receiver);
        $method = 'set' . $setterName; //eg. setConfigManager
        if (method_exists($Receiver, $method) === false) {
            throw new UndefinedDependencySetterException([
                $method,
                $setterName,
                $receiverClassName,
            ]);
        }

        $Dependency = $this->resolve($setterName);
        $Receiver->$method($Dependency);

        $this->getInjectedCollection()->set($receiverClassName, true);
    }

    /**
     * @param $className
     * @param bool $autoload
     *
     * @return array
     */
    protected function getClassSetterDependencies($className, $autoload = true)
    {
        if ($this->getClassDependencyCollection()->has($className)) {
            return $this->getClassDependencyCollection()->get($className);
        }

        $traits = class_uses($className, $autoload);
        $parents = class_parents($className, $autoload);

        foreach ($parents as $parent) {
            $traits = array_merge(
                class_uses($parent, $autoload),
                $traits
            );
        }

        $dependencies = array_keys($traits);
        $dependencies = array_filter($dependencies, function($dependencyName){
            return $this->isSetterInjection($dependencyName);
        });

        $this->getClassDependencyCollection()->set($className, $dependencies);

        return $this->getClassDependencyCollection()->get($className);
    }

    /**
{'fraction_non_alphanumeric': 0.10876500075953213, 'fraction_numerical': 0.0, 'mean_word_length': 3.012187690432663, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 35, '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': '491971', 'n_tokens_mistral': 1731, 'n_tokens_neox': 1661, 'n_words': 323}