Qa\SoftMocks::doRewrite PHP Method

doRewrite() private static method

private static doRewrite ( $file )
    private static function doRewrite($file)
    {
        if ($file[0] != '/') {
            foreach (explode(':', get_include_path()) as $dir) {
                if ($dir == '.') {
                    $bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
                    $dir = dirname(self::replaceFilename($bt[1]['file'], true));
                }
                if (file_exists($dir . '/' . $file)) {
                    $file = "{$dir}/{$file}";
                    break;
                }
            }
        } else {
            $file = realpath($file);
        }
        if (!$file) {
            return $file;
        }
        if (!isset(self::$rewrite_cache[$file])) {
            if (strpos($file, self::$mocks_cache_path) === 0 || strpos($file, self::getVersion() . DIRECTORY_SEPARATOR) === 0 || strpos($file, self::$phpunit_path) !== false || strpos($file, self::$php_parser_path) !== false) {
                return $file;
            }
            if (isset(self::$ignore[$file])) {
                return $file;
            }
            $md5_file = md5_file($file);
            if (!$md5_file) {
                return self::$orig_paths[$file] = self::$rewrite_cache[$file] = $file;
            }
            $clean_filepath = $file;
            if (strpos($clean_filepath, SOFTMOCKS_ROOT_PATH) === 0) {
                $clean_filepath = substr($clean_filepath, strlen(SOFTMOCKS_ROOT_PATH));
            }
            if (self::$debug) {
                self::debug("Clean filepath for {$file} is {$clean_filepath}");
            }
            $md5 = md5($clean_filepath . ':' . $md5_file);
            $target_file = self::$mocks_cache_path . self::getVersion() . DIRECTORY_SEPARATOR . substr($md5, 0, 2) . DIRECTORY_SEPARATOR . basename($file) . "_" . $md5 . ".php";
            if (!file_exists($target_file)) {
                $old_umask = umask(0);
                self::createRewrittenFile($file, $target_file);
                umask($old_umask);
                /* simulate atime to prevent deletion files in use by SoftMocksCleaner */
            } else {
                if (time() - filemtime($target_file) > self::MOCKS_CACHE_TOUCHTIME) {
                    touch($target_file);
                }
            }
            $target_file = realpath($target_file);
            self::$rewrite_cache[$file] = $target_file;
            self::$orig_paths[$target_file] = $file;
        }
        return self::$rewrite_cache[$file];
    }