<commit_before><?php

namespace CallableArgumentsResolver\ArgumentMatcher;

class InDepthArgumentMatcher implements ArgumentMatcher
{
    /**
     * {@inheritdoc}
     */
    public function filter(array $parameters)
    {
        uasort($parameters, [__CLASS__, 'compareParameters']);

        return $parameters;
    }

    /**
     * {@inheritdoc}
     */
    public function match(\ReflectionParameter $parameter, array $parameters)
    {
        $found = false;

        foreach ($parameters as $key => $value) {
            if (!$this->matchType($parameter, $value)) {
                continue;
            }

            if ($key === $parameter->name) {
                return $key;
            }

            if (false === $found) {
                $found = $key;
            }
        }

        return $found;
    }

    /**
     * Checks if the value match the parameter type.
     *
     * @param \ReflectionParameter $parameter
     * @param mixed                $value
     *
     * @return bool
     */
    protected function matchType(\ReflectionParameter $parameter, $value)
    {
        if ($class = $parameter->getClass()) {
            return is_object($value) && $class->isInstance($value);
        }

        if ($parameter->isArray()) {
            return is_array($value);
        }

        if ($parameter->isCallable()) {
            return is_callable($value);
        }

        return true;
    }

    /**
     * Compares parameters by type and optionality.
     *
     * @param \ReflectionParameter $a
     * @param \ReflectionParameter $b
     *<commit_msg>Fix a typo<commit_after><?php

namespace CallableArgumentsResolver\ArgumentMatcher;

class InDepthArgumentMatcher implements ArgumentMatcher
{
    /**
     * {@inheritdoc}
     */
    public function filter(array $parameters)
    {
        uasort($parameters, [__CLASS__, 'compareParameters']);

        return $parameters;
    }

    /**
     * {@inheritdoc}
     */
    public function match(\ReflectionParameter $parameter, array $parameters)
    {
        $found = false;

        foreach ($parameters as $key => $value) {
            if (!$this->matchType($parameter, $value)) {
                continue;
            }

            if ($key === $parameter->name) {
                return $key;
            }

            if (false === $found) {
                $found = $key;
            }
        }

        return $found;
    }

    /**
     * Checks if the value matches the parameter type.
     *
     * @param \ReflectionParameter $parameter
     * @param mixed                $value
     *
     * @return bool
     */
    protected function matchType(\ReflectionParameter $parameter, $value)
    {
        if ($class = $parameter->getClass()) {
            return is_object($value) && $class->isInstance($value);
        }

        if ($parameter->isArray()) {
            return is_array($value);
        }

        if ($parameter->isCallable()) {
            return is_callable($value);
        }

        return true;
    }

    /**
     * Compares parameters by type and optionality.
     *
     * @param \ReflectionParameter $a
     * @param \ReflectionParameter $b
     *
{'fraction_non_alphanumeric': 0.12275731822474033, 'fraction_numerical': 0.0, 'mean_word_length': 1.7139197267292912, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '245500', 'n_tokens_mistral': 844, 'n_tokens_neox': 821, 'n_words': 194}