<commit_before><?php declare(strict_types = 1);

namespace DaveRandom\CallbackValidator;

final class CallbackType
{
    /**
     * @var ReturnType
     */
    private $returnType;

    /**
     * @var ParameterType[]
     */
    private $parameters;

    /**
     * Given a callable, create the appropriate reflection
     *
     * This will accept things the PHP would fail to invoke due to scoping, but we can reflect them anyway. Do not add
     * a callable type-hint or this behaviour will break!
     *
     * @param callable $callback
     * @return \ReflectionFunction|\ReflectionMethod
     * @throws \ReflectionException
     */
    private static function reflectCallable($callback)
    {
        if ($callback instanceof \Closure) {
            return new \ReflectionFunction($callback);
        }

        if (\is_array($callback)) {
            return new \ReflectionMethod($callback[0], $callback[1]);
        }

        if (\is_object($callback)) {
            return new \ReflectionMethod($callback, '__invoke');
        }

        return \strpos($callback, '::') !== false
            ? new \ReflectionMethod($callback)
            : new \ReflectionFunction($callback);
    }

    /**
     * @param ReturnType $returnType<commit_msg>Tighten CallbackType::reflectCallable()<commit_after><?php declare(strict_types = 1);

namespace DaveRandom\CallbackValidator;

final class CallbackType
{
    /**
     * @var ReturnType
     */
    private $returnType;

    /**
     * @var ParameterType[]
     */
    private $parameters;

    /**
     * Given a callable, create the appropriate reflection
     *
     * This will accept things the PHP would fail to invoke due to scoping, but we can reflect them anyway. Do not add
     * a callable type-hint or this behaviour will break!
     *
     * @param callable $callback
     * @return \ReflectionFunction|\ReflectionMethod
     * @throws \ReflectionException
     */
    private static function reflectCallable($callback)
    {
        if ($callback instanceof \Closure) {
            return new \ReflectionFunction($callback);
        }

        if (\is_array($callback) && isset($callback[0], $callback[1])) {
            return new \ReflectionMethod($callback[0], $callback[1]);
        }

        if (\is_object($callback) && \method_exists($callback, '__invoke')) {
            return new \ReflectionMethod($callback, '__invoke');
        }

        $callback = (string)$callback;

        return \strpos($callback, '::') !== false
            ? new \ReflectionMethod($callback)
            : new \ReflectionFunction((string)$callback);
    }

    /**
     * @param ReturnType $returnType
{'fraction_non_alphanumeric': 0.11596385542168675, 'fraction_numerical': 0.0030120481927710845, 'mean_word_length': 2.4372574385510997, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '5791174', 'n_tokens_mistral': 698, 'n_tokens_neox': 683, 'n_words': 192}