<commit_before><?php

namespace Framework\Service\Resolver;

use ReflectionFunction;
use ReflectionMethod;
use RuntimeException;

trait SignalTrait
{
    /**
     * @param callable $config
     * @param array $args
     * @param callable $callback
     * @return mixed
     */
    protected function signal(callable $config, array $args = [], callable $callback = null)
    {
        $callable = null;
        $matched  = [];
        $method   = '__invoke';
        $params   = null;

        if ($args && !is_string(key($args))) {
            return call_user_func_array($config, $args);
        }

        if (is_array($config)) {
            isset($config[1]) && $method = $config[1];
            $config = $config[0];
        }

        if (is_string($config) && !class_exists($config)) {
            $static = explode(ResolverInterface::CALLABLE_STRING, $config);
            if ($static && isset($static[1])) {
                list($config, $method) = $static;
            } else {
                $params   = (new ReflectionFunction($config))->getParameters();
                $callable = $config;
            }
        }

        !$params && $params = (new ReflectionMethod($config, $method))->getParameters();

        foreach($params as $param) {
            if (isset($args[$param->name])) {
                $matched[] = $args[$param->name];
                continue;
            }

            if (ResolverInterface::ARGS === $param->name) {
                $matched[] = $args;
                continue;
            }

            if ($callback && $match = $callback($param->name)) {
                $matched[] = $match;
                continue;
            }

            if ($param->isDefaultValueAvailable()) {
                $matched[] = $param->getDefaultValue();
                continue;
            }

            if ($param->isArray()) {<commit_msg>plugins shouldn't be optional ?<commit_after><?php

namespace Framework\Service\Resolver;

use ReflectionFunction;
use ReflectionMethod;
use RuntimeException;

trait SignalTrait
{
    /**
     * @param callable $config
     * @param array $args
     * @param callable $callback
     * @return mixed
     */
    protected function signal(callable $config, array $args = [], callable $callback = null)
    {
        $callable = null;
        $matched  = [];
        $method   = '__invoke';
        $params   = null;

        if ($args && !is_string(key($args))) {
            return call_user_func_array($config, $args);
        }

        if (is_array($config)) {
            isset($config[1]) && $method = $config[1];
            $config = $config[0];
        }

        if (is_string($config) && !class_exists($config)) {
            $static = explode(ResolverInterface::CALLABLE_STRING, $config);
            if ($static && isset($static[1])) {
                list($config, $method) = $static;
            } else {
                $params   = (new ReflectionFunction($config))->getParameters();
                $callable = $config;
            }
        }

        !$params && $params = (new ReflectionMethod($config, $method))->getParameters();

        foreach($params as $param) {
            if (isset($args[$param->name])) {
                $matched[] = $args[$param->name];
                continue;
            }

            if (ResolverInterface::ARGS === $param->name) {
                $matched[] = $args;
                continue;
            }

            if ($callback && !$param->isOptional() && $match = $callback($param->name)) {
                $matched[] = $match;
                continue;
            }

            if ($param->isDefaultValueAvailable()) {
                $matched[] = $param->getDefaultValue();
                continue;
            }

            if ($param->isArray()) {
{'fraction_non_alphanumeric': 0.14893055188803803, 'fraction_numerical': 0.002112490097702667, 'mean_word_length': 1.733044733044733, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 22, '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': '5612225', 'n_tokens_mistral': 1037, 'n_tokens_neox': 1001, 'n_words': 209}