<commit_before><?php

class CMTest_TH {

    private static $_timeStart;
    private static $timeDelta = 0;
    private static $_configBackup;
    private static $_serviceManagerBackup;

    public static function init() {
        $output = new CM_OutputStream_Null();
        $loader = CM_App::getInstance()->getProvisionLoader();
        $loader->unload($output);
        $loader->load($output);

        self::$_configBackup = serialize(CM_Config::get());
        $serviceManager = CM_Service_Manager::getInstance();
        self::$_serviceManagerBackup = clone $serviceManager;

        // Reset environment
        self::clearEnv();
        self::randomizeAutoincrement();
        self::timeInit();
    }

    public static function clearEnv() {
        self::clearConfig();
        self::clearServices();
        self::clearDb();
        self::clearCache();
        self::timeReset();
        self::clearFilesystem();
    }

    public static function clearCache() {
        CM_Cache_Shared::getInstance()->flush();
        CM_Cache_Local::getInstance()->flush();
    }

    public static function clearConfig() {
        CM_Config::set(unserialize(self::$_configBackup));
    }

    public static function clearFilesystem() {
        $script = new CM_File_Filesystem_SetupScript(CM_Service_Manager::getInstance());
        $script->unload(new CM_OutputStream_Null());
    }

    public static function clearServices() {
        CM_Service_Manager::setInstance(clone self::$_serviceManagerBackup);
    }

    public static function timeInit() {
        if (!isset(self::$_timeStart)) {
            timecop_return();
            $time = time();
            timecop_freeze($time);
        }
        self::$_timeStart = time();
        self::$timeDelta = 0;
    }

    public static function time() {
        return self::$_timeStart + self::$timeDelta;
    }

    public static function gettimeofday($returnFloat = null) {
        $pseudoTime = self::time();
        if ($returnFloat) {
            return $pseudoTime + 0.1234;
        }
        $dateStruct = gettimeofday();
        $dateStruct['sec'] = $pseudoTime;
        $dateStruct['usec'] = 123456;
        return $dateStruct;
    }

    public static function timeForward($sec) {
        self::$timeDelta += $sec;
        timecop_freeze(self::time());
    }

    public static function timeDaysForward($days) {
        self::timeForward($days * 24 * 60 * 60);
    }

    public static function timeReset() {
        self::$timeDelta = 0;
        timecop_freeze(self::time());
    }

    public static function timeDelta() {
        return self::$timeDelta;
    }

    public static function timeDiffInDays($stamp1, $stamp2) {
        return round(($stamp2 - $stamp1) / (60 * 60 * 24));
    }

    /**
     * @return CM_Service_Manager
     */
    public static function getServiceManager() {
        return CM_Service_Manager::getInstance();
    }
<commit_msg>Remove CMTest_TH::gettimeofday() as no more usages<commit_after><?php

class CMTest_TH {

    private static $_timeStart;
    private static $timeDelta = 0;
    private static $_configBackup;
    private static $_serviceManagerBackup;

    public static function init() {
        $output = new CM_OutputStream_Null();
        $loader = CM_App::getInstance()->getProvisionLoader();
        $loader->unload($output);
        $loader->load($output);

        self::$_configBackup = serialize(CM_Config::get());
        $serviceManager = CM_Service_Manager::getInstance();
        self::$_serviceManagerBackup = clone $serviceManager;

        // Reset environment
        self::clearEnv();
        self::randomizeAutoincrement();
        self::timeInit();
    }

    public static function clearEnv() {
        self::clearConfig();
        self::clearServices();
        self::clearDb();
        self::clearCache();
        self::timeReset();
        self::clearFilesystem();
    }

    public static function clearCache() {
        CM_Cache_Shared::getInstance()->flush();
        CM_Cache_Local::getInstance()->flush();
    }

    public static function clearConfig() {
        CM_Config::set(unserialize(self::$_configBackup));
    }

    public static function clearFilesystem() {
        $script = new CM_File_Filesystem_SetupScript(CM_Service_Manager::getInstance());
        $script->unload(new CM_OutputStream_Null());
    }

    public static function clearServices() {
        CM_Service_Manager::setInstance(clone self::$_serviceManagerBackup);
    }

    public static function timeInit() {
        if (!isset(self::$_timeStart)) {
            timecop_return();
            $time = time();
            timecop_freeze($time);
        }
        self::$_timeStart = time();
        self::$timeDelta = 0;
    }

    public static function time() {
        return self::$_timeStart + self::$timeDelta;
    }

    public static function timeForward($sec) {
        self::$timeDelta += $sec;
        timecop_freeze(self::time());
    }

    public static function timeDaysForward($days) {
        self::timeForward($days * 24 * 60 * 60);
    }

    public static function timeReset() {
        self::$timeDelta = 0;
        timecop_freeze(self::time());
    }

    public static function timeDelta() {
        return self::$timeDelta;
    }

    public static function timeDiffInDays($stamp1, $stamp2) {
        return round(($stamp2 - $stamp1) / (60 * 60 * 24));
    }

    /**
     * @return CM_Service_Manager
     */
    public static function getServiceManager() {
        return CM_Service_Manager::getInstance();
    }

{'fraction_non_alphanumeric': 0.12972972972972974, 'fraction_numerical': 0.008828828828828829, 'mean_word_length': 2.695739014647137, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '4728601', 'n_tokens_mistral': 1568, 'n_tokens_neox': 1516, 'n_words': 311}