<commit_before><?php
class Wpup_UpdateServer {
	protected $packageDirectory;
	protected $logDirectory;
	protected $cache;
	protected $serverUrl;
	protected $startTime = 0;

	public function __construct($serverUrl = null, $serverDirectory = null) {
		if ( $serverDirectory === null ) {
			$serverDirectory = realpath(__DIR__ . '/../..');
		}
		if ( $serverUrl === null ) {
			$serverUrl = self::determineServerUrl();
		}

		$this->serverUrl = $serverUrl;
		$this->packageDirectory = $serverDirectory . '/packages';
		$this->logDirectory = $serverDirectory . '/logs';
		$this->cache = new Wpup_FileCache($serverDirectory . '/cache');
	}

	/**
	 * Determine the Server Url based on the current request.
	 *
	 * Defaults to the current URL minus the query and "index.php".
	 *
	 * @static
	 *
	 * @return string Url
	 */
	public static function determineServerUrl() {
		$serverUrl = ( self::isSsl() ? 'https' : 'http' );
		$serverUrl .= '://' . $_SERVER['HTTP_HOST'];
		$path = $_SERVER['SCRIPT_NAME'];
		if ( basename($path) === 'index.php' ) {
			$path = dirname($path) . '/';
		}
		$serverUrl .= $path;
		return $serverUrl;
	}

	/**
	 * Determine if ssl is used.
	 *
	 * @return bool True if SSL, false if not used.
	 */
    public static function isSsl() {
        if ( isset($_SERVER['HTTPS']) ) {
            if ( 'on' === strtolower($_SERVER['HTTPS']) ) {
                return true;
			}
	        if ( '1' == $_SERVER['HTTPS'] ) {
                return true;
            }
        }
		elseif ( isset($_SERVER['SERVER_PORT']) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
            return true;
		}
        return false;
	}

	/**
	 * Process an update API request.
	 *
	 * @param array|null $query Query parameters. Defaults to the current request parameters (GET + POST).
	 */
	public function handleRequest($query = null) {
		$this->startTime = microtime(true);<commit_msg>Fix issues with dirname() on Windows<commit_after><?php
class Wpup_UpdateServer {
	protected $packageDirectory;
	protected $logDirectory;
	protected $cache;
	protected $serverUrl;
	protected $startTime = 0;

	public function __construct($serverUrl = null, $serverDirectory = null) {
		if ( $serverDirectory === null ) {
			$serverDirectory = realpath(__DIR__ . '/../..');
		}
		if ( $serverUrl === null ) {
			$serverUrl = self::determineServerUrl();
		}

		$this->serverUrl = $serverUrl;
		$this->packageDirectory = $serverDirectory . '/packages';
		$this->logDirectory = $serverDirectory . '/logs';
		$this->cache = new Wpup_FileCache($serverDirectory . '/cache');
	}

	/**
	 * Determine the Server Url based on the current request.
	 *
	 * Defaults to the current URL minus the query and "index.php".
	 *
	 * @static
	 *
	 * @return string Url
	 */
	public static function determineServerUrl() {
		$serverUrl = ( self::isSsl() ? 'https' : 'http' );
		$serverUrl .= '://' . $_SERVER['HTTP_HOST'];
		$path = $_SERVER['SCRIPT_NAME'];

		if ( basename($path) === 'index.php' ) {
			if ( DIRECTORY_SEPARATOR === '/' ) {
				$path = dirname($path) . '/';
			}
			else {
				// Fix Windows
				if ( dirname($path) === '\\' ) {
					$path = '/';
				}
				else {
					$path = str_replace('\\', '/', dirname($path)) . '/';
				}
			}
		}

		$serverUrl .= $path;
		return $serverUrl;
	}
	/**
	 * Determine if ssl is used.
	 *
	 * @return bool True if SSL, false if not used.
	 */
    public static function isSsl() {
        if ( isset($_SERVER['HTTPS']) ) {
            if ( 'on' === strtolower($_SERVER['HTTPS']) ) {
                return true;
			}
	        if ( '1' == $_SERVER['HTTPS'] ) {
                return true;
            }
        }
		elseif ( isset($_SERVER['SERVER_PORT']) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
            return true;
		}
        return false;
	}

	/**
	 * Process an update API request.
	 *
	 * @param array|null $query Query parameters. Defaults to the current request parameters (GET + POST).
	 */
	public function handleRequest($query = null) {
		$this->startTime = microtime(true);
{'fraction_non_alphanumeric': 0.16720819795051237, 'fraction_numerical': 0.0024993751562109472, 'mean_word_length': 2.75422138836773, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2337664', 'n_tokens_mistral': 1395, 'n_tokens_neox': 1252, 'n_words': 312}