<commit_before><?php namespace core\traits;

trait ClassMethods
{
    protected static function validateNumArgs($function, $numArgs, $min = 0, $max = 0)
    {
        $namespace = explode('\\', self::getClassName());
        $class = $namespace[(count($namespace) - 1)];

        if ($numArgs >= $min and $numArgs <= $max) {
            return true;
        }
        if ($numArgs > $max) {
            $msg = $class . "::" . $function . "() expects at most " . $max . (($max > 1) ? " parameters, " : " parameter, ") . $numArgs . " given.";
        }
        if ($numArgs < $min) {
            $msg = $class . "::" . $function . "() expects at least " . $min . (($min > 1) ? " parameters, " : " parameter, ") . $numArgs . " given.";
        }
        if ($max == 0 and $numArgs > 0) {
            $msg = $class . "::" . $function . "() doesn't expect any parameter.";
        }

        $_SESSION['debug_backtrace_file'] = debug_backtrace()[1]['file'];
        $_SESSION['debug_backtrace_line'] = debug_backtrace()[1]['line'];

        trigger_error($msg, E_USER_WARNING);
    }

    protected static function getClassName()
    {
        return __CLASS__;
    }

    protected static function validateArgType($function, $arg, $number, $types)
    {
        $namespace = explode('\\', self::getClassName());
        $class = $namespace[(count($namespace) - 1)];

        $expects = implode(' or ', $types);

        $valid = false;

        foreach ($types as $type) {
            switch ($type) {
                case 'null':
                    if (is_null($arg)) {
                        $valid = true;
                    }
                    break;
                case 'array':
                    if (is_array($arg)) {
                        $valid = true;
                    }
                    break;
                case 'object':
                    if (is_object($arg)) {
                        $valid = true;
                    }
                    break;
                case 'bool':
                    if (is_bool($arg)) {
                        $valid = true;
                    }
                    break;
                case 'string':
                    if (is_string($arg)) {
                        $valid = true;
                    }
                    break;
                case 'integer':
                    if (is_integer($arg)) {
                        $valid = true;
                    }
                    break;
                case 'float':
                    if (is_float($arg)) {
                        $valid = true;
                    }
                    break;
            }
        }
        if (!$valid) {

            $_SESSION['debug_backtrace_file'] = debug_backtrace()[1]['file'];
            $_SESSION['debug_backtrace_line'] = debug_backtrace()[1]['line'];

            $msg = $class . "::" . $function . "() expects parameter " . $number . " to be " . $expects . ", " . gettype($arg) . " given.";

            trigger_error($msg, E_USER_WARNING);
        }
    }
}<commit_msg>Tratado o método privado getClassName.<commit_after><?php namespace core\traits;

trait ClassMethods
{
    private static function getClassName()
    {
        $namespace = (strrpos(__CLASS__, 'ClassMethods')) ? '' : __CLASS__;
        $parts = explode('\\', $namespace);
        $class = $parts[(count($parts) - 1)];
        return $class . '::';
    }

    public static function validateNumArgs($function, $numArgs, $min = 0, $max = 0)
    {
        if ($numArgs >= $min and $numArgs <= $max) {
            return true;
        }
        if ($numArgs > $max) {
            $msg = self::getClassName() . $function . "() expects at most " . $max . (($max > 1) ? " parameters, " : " parameter, ") . $numArgs . " given.";
        }
        if ($numArgs < $min) {
            $msg = self::getClassName() . $function . "() expects at least " . $min . (($min > 1) ? " parameters, " : " parameter, ") . $numArgs . " given.";
        }
        if ($max == 0 and $numArgs > 0) {
            $msg = self::getClassName() . $function . "() doesn't expect any parameter.";
        }

        $_SESSION['debug_backtrace_file'] = debug_backtrace()[1]['file'];
        $_SESSION['debug_backtrace_line'] = debug_backtrace()[1]['line'];

        trigger_error($msg, E_USER_WARNING);
    }

    public static function validateArgType($function, $arg, $number, $types)
    {
        $valid = false;

        foreach ($types as $type) {
            switch ($type) {
                case 'null':
                    if (is_null($arg)) {
                        $valid = true;
                    }
                    break;
                case 'array':
                    if (is_array($arg)) {
                        $valid = true;
                    }
                    break;
                case 'object':
                    if (is_object($arg)) {
                        $valid = true;
                    }
                    break;
                case 'bool':
                    if (is_bool($arg)) {
                        $valid = true;
                    }
                    break;
                case 'string':
                    if (is_string($arg)) {
                        $valid = true;
                    }
                    break;
                case 'integer':
                    if (is_integer($arg)) {
                        $valid = true;
                    }
                    break;
                case 'float':
                    if (is_float($arg)) {
                        $valid = true;
                    }
                    break;
                case 'double':
                    if (is_double($arg)) {
                        $valid = true;
                    }
                    break;
            }
        }
        if (!$valid) {

            $expects = implode(' or ', $types);

            $_SESSION['debug_backtrace_file'] = debug_backtrace()[1]['file'];
            $_SESSION['debug_backtrace_line'] = debug_backtrace()[1]['line'];

            $msg = self::getClassName() . $function . "() expects parameter " . $number . " to be " . $expects . ", " . gettype($arg) . " given.";

            trigger_error($msg, E_USER_WARNING);
        }
    }
}
{'fraction_non_alphanumeric': 0.1450296142148231, 'fraction_numerical': 0.003681767248279174, 'mean_word_length': 1.1808027923211168, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 13, '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': '4104647', 'n_tokens_mistral': 1716, 'n_tokens_neox': 1603, 'n_words': 365}