<commit_before><?php

Imports("System.Diagnostics.StackTrace");

class Enum {

    /** 
     * 类型枚举缓存
     * 
     * @var array
    */
    private static $enumTypes = [];

    /**
     * 这个函数会自动根据栈信息来查找枚举类型
     * 
     * 调用函数必须要定义在枚举类之中，否则会找不到正确的栈片段信息
     * 
     * @param integer $value 枚举值
    */
    public static function ToString($value) {
        $stack     = StackTrace::GetCallStack();
        $type      = $stack->GetFrame(2);
        $type      = $type->frame["class"];
        $reflector = new ReflectionClass($type);
        
        if (!array_key_exists($type, self::$enumTypes)) {
            $dataEnum = $reflector->getConstants();
            $toString = [];

            foreach($dataEnum as $name => $value) {
                $toString[strval($value)] = $name;
            }

            self::$enumTypes[$type] = $toString;
        }

        return self::$enumTypes[$type][strval($value)];
    }
}<commit_msg>fix tostring bugs<commit_after><?php

Imports("System.Diagnostics.StackTrace");

class Enum {

    /** 
     * 类型枚举缓存
     * 
     * @var array
    */
    private static $enumTypes = [];

    /**
     * 这个函数会自动根据栈信息来查找枚举类型
     * 
     * 调用函数必须要定义在枚举类之中，否则会找不到正确的栈片段信息
     * 
     * @param integer $value 枚举值
    */
    public static function ToString($value) {
        $stack     = StackTrace::GetCallStack();
        $type      = $stack->GetFrame(2);
        $type      = $type->frame["class"];
        $reflector = new ReflectionClass($type);
        $key       = "T" . strval($value);        

        if (!array_key_exists($type, self::$enumTypes)) {
            $dataEnum = $reflector->getConstants();
            $toString = [];

            foreach($dataEnum as $name => $val) {
                $toString["T" . strval($val)] = $name;
            }

            self::$enumTypes[$type] = $toString;
        }

        return self::$enumTypes[$type][$key];
    }
}
{'fraction_non_alphanumeric': 0.1534419337887546, 'fraction_numerical': 0.0010509721492380452, 'mean_word_length': 1.8674698795180722, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '4520507', 'n_tokens_mistral': 661, 'n_tokens_neox': 695, 'n_words': 96}