<commit_before><?php
/**
 *
 */

namespace Mvc5\Plugin;

use Mvc5\Config\Scope as _Scope;
use Mvc5\Service\Service as _Service;

/**
 * Creates an object with a Plugins container and sets the object as the scope of the anonymous functions. If the
 * object is cloned, it will need a clone method to workaround the recursion problem.
 */
class Scope
    extends Call
{
    /**
     *
     */
    const APP_CLASS = 'Mvc5\App';

    /**
     * @param $name
     * @param array $config
     * @param array ...$args
     */
    function __construct($name, $config = [], ...$args)
    {
        parent::__construct([$this, 'scope'], [new Link, $this->plugins($config), $name, new Args($args)]);
    }

    /**
     * @param $config
     * @return Plugin|Plugins
     */
    protected function plugins($config)
    {
        return $config instanceof Plugins || $config instanceof Plugin || $config instanceof Plug  ? $config :
            new Plugin(static::APP_CLASS, [$config, new Link]);
    }

    /**
     * @param _Service $service
     * @param _Scope $plugins
     * @param string $name
     * @param array $args
     * @return callable|null|object
     */
    function scope(_Service $service, _Scope $plugins, $name, array $args = [])
    {
        array_unshift($args, $plugins);

        $plugin = $service->plugin($name, $args);

        $plugins->scope($plugin);

        return $plugin;
    }
}
<commit_msg>pass scope plugin first object in $args<commit_after><?php
/**
 *
 */

namespace Mvc5\Plugin;

use Mvc5\Service\Service as _Service;

/**
 * Creates an object with a Plugins container and sets the object as the scope of the anonymous functions. If the
 * object is cloned, it will need a clone method to workaround the recursion problem.
 */
class Scope
    extends Call
{
    /**
     * @param $name
     * @param array $args
     */
    function __construct($name, array $args)
    {
        parent::__construct([$this, 'scope'], [$name, new Link, new Args($args)]);
    }

    /**
     * @param string $name
     * @param _Service $service
     * @param array $args
     * @return callable|null|object
     */
    function scope($name, _Service $service, array $args)
    {
        $plugin = $service->plugin($name, $args);

        $args[0]->scope($plugin);

        return $plugin;
    }
}

{'fraction_non_alphanumeric': 0.13587191691908265, 'fraction_numerical': 0.003028991778450887, 'mean_word_length': 2.5190258751902586, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '7017831', 'n_tokens_mistral': 704, 'n_tokens_neox': 688, 'n_words': 215}