<commit_before><?php

function tool_yaml_load(array $files, bool $log_errors = true)
{
    $data = [];

    foreach ($files as $file) {
        if (!is_file($file)) {
            continue;
        }

        $content = @file_get_contents($file);
        if ($content === false) {
            continue;
        }

        try
        {
            $content = \Symfony\Component\Yaml\Yaml::parse($content);
        } catch (Exception $e) {
            log_if_err($log_errors, 'unable to parse yaml file contents, file: ' . $file . ', error: ' . $e->getMessage());
            continue;
        }

        if (is_array($content)) {
            $data = array_replace_recursive($data, $content);
        }
    }

    return $data;
}

function tool_call_parse($call, array $args = [], $log = true)
{
    /* bit of backwards compatibility */
    if (!isset($call['call']) && isset($call['class']) && isset($call['method']) && is_string($call['class']) && is_string($call['method'])) {
        $call['call'] = $call['class'] . '@' . $call['method'];
    }

    /* check that call is defined */
    if (!isset($call['call']) || !is_string($call['call'])) {
        return null;
    }

    /* parse args */
    if (isset($call['args']) && is_array($call['args'])) {
        $args = array_merge($call['args'], $args);
    }
    $parts = explode('(', $call['call'], 2);
    if (count($parts) == 2) {
        $args = array_merge(['null' => null, 'true' => true, 'false' => false], $args);
        if (substr($parts[1], -1) != ')') {
            log_err('call parsing failed, missing ")" from end of call {0}', [$call['call']]);
            return null;
        }
        $names = explode(',', substr($parts[1], 0, -1));
        if ($names[0] == '') {
            array_shift($names);
        }
        $new_args = [];
        foreach ($names as $name) {
            $name = trim($name);
            if (tool_validate('number', $name)) {
                tool_validate('int', $name); /* this converts value ($name) to int if it can be done */
                $new_args[] = $name;
            } else if (!array_key_exists($name, $args)) {
                log_err('call parsing failed, missing argument "{arg}" for call {call}', ['call' => $call['call'], 'arg' => $name]);
                return null;
            } else {
                $new_args[] = $args[$name];
            }
        }
        $args = $new_args;
    }

    /* separate class and method, if there are such */
    $parts = explode('@', $parts[0], 2);

    /* function call */
    if (count($parts) == 1) {
        if (!function_exists($call['call'])) {
            log_if_err($log, 'call parsing failed, function does not exist: ' . $call['call']);
            return null;
        }
        return ['function' => new ReflectionFunction($call['call']), 'args' => $args];
    }

    /* method call */
    if (!class_exists($parts[0])) {
        log_if_err($log, 'call parsing failed, class does not exist: ' . $call['call']);
        return null;
    }
    $class = new ReflectionClass($parts[0]);
    if (!$class->hasMethod($parts[1])) {
        log_if_err($log, 'call parsing failed, method does not exist: ' . $call['call']);
        return null;
    }
    $method = $class->getMethod($parts[1]);

    /* if method is static, this is simple and just return it */
    if ($method->isStatic()) {
        return ['object' => null, 'method' => $method, 'args' => $args];
    }

    /* method is not static, check if class can be constructed without parameters */
    if ($class->hasMethod('__construct') && $class->getMethod('__construct')->getNumberOfRequiredParameters() > 0) {<commit_msg>bug fix to function call<commit_after><?php

function tool_yaml_load(array $files, bool $log_errors = true)
{
    $data = [];

    foreach ($files as $file) {
        if (!is_file($file)) {
            continue;
        }

        $content = @file_get_contents($file);
        if ($content === false) {
            continue;
        }

        try
        {
            $content = \Symfony\Component\Yaml\Yaml::parse($content);
        } catch (Exception $e) {
            log_if_err($log_errors, 'unable to parse yaml file contents, file: ' . $file . ', error: ' . $e->getMessage());
            continue;
        }

        if (is_array($content)) {
            $data = array_replace_recursive($data, $content);
        }
    }

    return $data;
}

function tool_call_parse($call, array $args = [], $log = true)
{
    /* bit of backwards compatibility */
    if (!isset($call['call']) && isset($call['class']) && isset($call['method']) && is_string($call['class']) && is_string($call['method'])) {
        $call['call'] = $call['class'] . '@' . $call['method'];
    }

    /* check that call is defined */
    if (!isset($call['call']) || !is_string($call['call'])) {
        return null;
    }

    /* parse args */
    if (isset($call['args']) && is_array($call['args'])) {
        $args = array_merge($call['args'], $args);
    }
    $parts = explode('(', $call['call'], 2);
    if (count($parts) == 2) {
        $args = array_merge(['null' => null, 'true' => true, 'false' => false], $args);
        if (substr($parts[1], -1) != ')') {
            log_err('call parsing failed, missing ")" from end of call {0}', [$call['call']]);
            return null;
        }
        $names = explode(',', substr($parts[1], 0, -1));
        if ($names[0] == '') {
            array_shift($names);
        }
        $new_args = [];
        foreach ($names as $name) {
            $name = trim($name);
            if (tool_validate('number', $name)) {
                tool_validate('int', $name); /* this converts value ($name) to int if it can be done */
                $new_args[] = $name;
            } else if (!array_key_exists($name, $args)) {
                log_err('call parsing failed, missing argument "{arg}" for call {call}', ['call' => $call['call'], 'arg' => $name]);
                return null;
            } else {
                $new_args[] = $args[$name];
            }
        }
        $args = $new_args;
    }

    /* separate class and method, if there are such */
    $parts = explode('@', $parts[0], 2);

    /* function call */
    if (count($parts) == 1) {
        if (!function_exists($parts[0])) {
            log_if_err($log, 'call parsing failed, function does not exist: ' . $call['call']);
            return null;
        }
        return ['function' => new ReflectionFunction($parts[0]), 'args' => $args];
    }

    /* method call */
    if (!class_exists($parts[0])) {
        log_if_err($log, 'call parsing failed, class does not exist: ' . $call['call']);
        return null;
    }
    $class = new ReflectionClass($parts[0]);
    if (!$class->hasMethod($parts[1])) {
        log_if_err($log, 'call parsing failed, method does not exist: ' . $call['call']);
        return null;
    }
    $method = $class->getMethod($parts[1]);

    /* if method is static, this is simple and just return it */
    if ($method->isStatic()) {
        return ['object' => null, 'method' => $method, 'args' => $args];
    }

    /* method is not static, check if class can be constructed without parameters */
    if ($class->hasMethod('__construct') && $class->getMethod('__construct')->getNumberOfRequiredParameters() > 0) {
{'fraction_non_alphanumeric': 0.189927267737066, 'fraction_numerical': 0.004940304652120214, 'mean_word_length': 2.2608501118568234, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, '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': '4272296', 'n_tokens_mistral': 2230, 'n_tokens_neox': 2179, 'n_words': 554}