<commit_before><?php

namespace Framework\Service\Provider;

use Framework\Config\ConfigInterface;
use Framework\Service\Config\Args\ArgsInterface as Args;
use Framework\Service\Config\Call\CallInterface as Call;
use Framework\Service\Config\Child\ChildInterface as Child;
use Framework\Service\Config\ConfigInterface as Config;
use Framework\Service\Config\ConfigLink\ConfigLinkInterface as ConfigLink;
use Framework\Service\Config\Dependency\DependencyInterface as Dependency;
use Framework\Service\Config\Filter\FilterInterface as Filter;
use Framework\Service\Config\Param\ParamInterface as Param;
use Framework\Service\Config\ServiceManagerLink\ServiceManagerLinkInterface as ServiceManagerLink;
use Framework\Service\Manager\ManagerInterface;

trait ProviderTrait
{
    /**
     * @param mixed $arg
     * @return mixed
     */
    protected function arg($arg)
    {
        /** @var ManagerInterface|self $this */

        if (!is_object($arg)) {
            return $arg;
        }

        if ($arg instanceof Child) {
            /** @var Child|Config $arg */

            $parent = clone $this->configured($this->arg($arg->parent()));

            $parent->add(Config::NAME, $this->arg($arg->name()));

            return $this->resolve($parent);
        }

        if ($arg instanceof Config) {
            return $this->resolve($arg);
        }

        if ($arg instanceof Dependency) {
            return $this->get($arg->name());
        }

        if ($arg instanceof Param) {
            return $this->arg($this->param($arg->name()));
        }

        if ($arg instanceof Call) {
            return $this->invoke($arg->config(), $arg->args());
        }

        if ($arg instanceof Args) {
            return $this->args($arg->config());
        }

        if ($arg instanceof Filter) {
            return $this->filter($this->arg($arg->config()), $arg->filter());
        }

        if ($arg instanceof ConfigLink) {
            return $this->config();
        }

        if ($arg instanceof ServiceManagerLink) {
            return $this;
        }

        return $arg;
    }

    /**
     * @param $args
     * @return mixed
     */
    protected function args($args)
    {
        if (!is_array($args)) {
            return $this->arg($args);
        }

        foreach($args as $index => $value) {
            $args[$index] = $this->arg($value);
        }

        return $args;
    }

    /**
     * @param callable|string $config
     * @param array $args
     * @return mixed
     */
    protected function call($config, array $args = [])
    {
        /** @var ManagerInterface|self $this */

        if (is_callable($config)) {<commit_msg>Service\Provider<commit_after><?php

namespace Framework\Service\Provider;

use Framework\Config\ConfigInterface;
use Framework\Service\Config\Args\ArgsInterface as Args;
use Framework\Service\Config\Call\CallInterface as Call;
use Framework\Service\Config\Child\ChildInterface as Child;
use Framework\Service\Config\ConfigInterface as Config;
use Framework\Service\Config\ConfigLink\ConfigLinkInterface as ConfigLink;
use Framework\Service\Config\Dependency\DependencyInterface as Dependency;
use Framework\Service\Config\Filter\FilterInterface as Filter;
use Framework\Service\Config\Param\ParamInterface as Param;
use Framework\Service\Config\ServiceManagerLink\ServiceManagerLinkInterface as ServiceManagerLink;
use Framework\Service\Manager\ManagerInterface;

trait ProviderTrait
{
    /**
     * @param mixed $arg
     * @return mixed
     */
    protected function arg($arg)
    {
        /** @var ManagerInterface|self $this */

        if (!is_object($arg)) {
            return $arg;
        }

        if ($arg instanceof Child) {
            /** @var Child|Config $arg */

            $parent = clone $this->configured($this->arg($arg->parent()));

            $parent->add(Config::NAME, $this->arg($arg->name()));

            return $this->resolve($parent);
        }

        if ($arg instanceof Config) {
            return $this->resolve($arg);
        }

        if ($arg instanceof Dependency) {
            return $this->get($arg->name());
        }

        if ($arg instanceof Param) {
            return $this->arg($this->param($arg->name()));
        }

        if ($arg instanceof Call) {
            return $this->invoke($arg->config(), $arg->args());
        }

        if ($arg instanceof Args) {
            return $this->args($arg->config());
        }

        if ($arg instanceof Filter) {
            return $this->filter($this->arg($arg->config()), $arg->filter());
        }

        if ($arg instanceof ConfigLink) {
            return $this->config();
        }

        if ($arg instanceof ServiceManagerLink) {
            return $this;
        }

        return $arg;
    }

    /**
     * @param $args
     * @return mixed
     */
    protected function args($args)
    {
        if (!is_array($args)) {
            return $this->arg($args);
        }

        foreach($args as $index => $value) {
            $args[$index] = $this->arg($value);
        }

        return $args;
    }

    /**
     * @param callable|string $config
     * @param array $args
     * @return mixed
     */
    protected function call($config, array $args = [])
    {
        /** @var ManagerInterface|self $this */

        if (!is_string($config) || false === strpos($config, '.')) {
{'fraction_non_alphanumeric': 0.14174107142857142, 'fraction_numerical': 0.0, 'mean_word_length': 2.2469806763285023, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 55, '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': '4539747', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1430, 'n_words': 328}