<commit_before><?php

class CM_Util {

	/**
	 * @param int $number
	 * @return int[]
	 */
	public static function decbinarr($number) {
		$bin = decbin($number);
		$binarr = array();
		for ($i = 0; $i < strlen($bin); $i++) {
			if (substr($bin, -$i - 1, 1) == 1) {
				$binarr[] = pow(2, $i);
			}
		}
		return $binarr;
	}

	/**
	 * Return human-readable information on one line about a variable
	 *
	 * @param mixed $expression
	 * @return string
	 */
	public static function var_line($expression) {
		$line = print_r($expression, true);
		$line = str_replace(PHP_EOL, ' ', $line);
		$line = trim($line);
		return $line;
	}

	/**
	 * @param string $pattern OPTIONAL
	 * @param string $path    OPTIONAL
	 * @return array
	 */
	public static function rglob($pattern = '*', $path = './') {
		$files = glob($path . $pattern, GLOB_NOSORT);
		sort($files); // glob's sort is not reliable (locale dependent?)
		$paths = glob($path . '*', GLOB_NOSORT | GLOB_MARK | GLOB_ONLYDIR);
		sort($paths);
		foreach ($paths as $path) {
			$files = array_merge($files, self::rglob($pattern, $path));
		}
		return $files;
	}

	/**
	 * @param string           $pattern
	 * @param CM_Site_Abstract $site
	 * @return string[]
	 */
	public static function rglobLibraries($pattern, CM_Site_Abstract $site) {
		$paths = array();
		foreach ($site->getNamespaces() as $namespace) {
			$libraryPath = CM_Util::getNamespacePath($namespace) . 'library/' . $namespace . '/';
			$paths = array_merge($paths, CM_Util::rglob($pattern, $libraryPath));
		}
		return $paths;
	}

	/**
	 * @param array $array
	 * @param mixed $value
	 * @return array
	 */
	public static function array_remove(array $array, $value) {
		return array_filter($array, function ($entry) use ($value) {
			return $value != $entry;
		});
	}

	/**
	 * @param string       $className
	 * @param boolean|null $ignoreInvalid
	 * @throws CM_Exception_Invalid
	 * @return string
	 */
	public static function getNamespace($className, $ignoreInvalid = null) {
		if (null === $ignoreInvalid) {
			$ignoreInvalid = false;
		}
		$ignoreInvalid = (boolean) $ignoreInvalid;
		$className = (string) $className;
		$tail = strpbrk($className, '_\\');
		$namespace = substr($className, 0, -strlen($tail));
		if (!$namespace) {
			if ($ignoreInvalid) {
				return null;
			}
			throw new CM_Exception_Invalid('Could not detect namespace of `' . $className . '`.');
		}
		return $namespace;
	}

	/**
	 * @param string       $url
	 * @param array|null   $params
	 * @param boolean|null $methodPost
	 * @param int|null     $timeout
	 * @throws CM_Exception_Invalid
	 * @return string
	 */
	public static function getContents($url, array $params = null, $methodPost = null, $timeout = null) {
		$url = (string) $url;
		if (!empty($params)) {
			$params = http_build_query($params);
		}
		if (null === $timeout) {
			$timeout = 10;
		}
		$timeout = (int) $timeout;

		$curlConnection = curl_init();
		curl_setopt($curlConnection, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($curlConnection, CURLOPT_TIMEOUT, $timeout);
		if ($methodPost) {
			curl_setopt($curlConnection, CURLOPT_POST, 1);
			if (!empty($params)) {
				curl_setopt($curlConnection, CURLOPT_POSTFIELDS, $params);
			}
		} else {
			if (!empty($params)) {
				$url .= '?' . $params;
			}
		}
		curl_setopt($curlConnection, CURLOPT_URL, $url);

		$contents = curl_exec($curlConnection);
		$curlError = null;
		if ($contents === false) {
			$curlError = 'Fetching contents from `' . $url . '` failed: `' . curl_error($curlConnection) . '`';
		}
		curl_close($curlConnection);
		if ($curlError) {
			throw new CM_Exception_Invalid($curlError);
		}
		return $contents;
	}

	/**
	 * @param string $xml
	 * @throws CM_Exception_Invalid
	 * @return SimpleXMLElement
	 */
	public static function parseXml($xml) {
		$xml = (string) $xml;

		$xml = @simplexml_load_string($xml);
		if (false === $xml) {
			throw new CM_Exception_Invalid('Could not parse xml');
		}

		return $xml;
	}

	/**
	 * @param string $path
	 * @return string
	 * @throws CM_Exception
	 */<commit_msg>Check if http_code is 200<commit_after><?php

class CM_Util {

	/**
	 * @param int $number
	 * @return int[]
	 */
	public static function decbinarr($number) {
		$bin = decbin($number);
		$binarr = array();
		for ($i = 0; $i < strlen($bin); $i++) {
			if (substr($bin, -$i - 1, 1) == 1) {
				$binarr[] = pow(2, $i);
			}
		}
		return $binarr;
	}

	/**
	 * Return human-readable information on one line about a variable
	 *
	 * @param mixed $expression
	 * @return string
	 */
	public static function var_line($expression) {
		$line = print_r($expression, true);
		$line = str_replace(PHP_EOL, ' ', $line);
		$line = trim($line);
		return $line;
	}

	/**
	 * @param string $pattern OPTIONAL
	 * @param string $path    OPTIONAL
	 * @return array
	 */
	public static function rglob($pattern = '*', $path = './') {
		$files = glob($path . $pattern, GLOB_NOSORT);
		sort($files); // glob's sort is not reliable (locale dependent?)
		$paths = glob($path . '*', GLOB_NOSORT | GLOB_MARK | GLOB_ONLYDIR);
		sort($paths);
		foreach ($paths as $path) {
			$files = array_merge($files, self::rglob($pattern, $path));
		}
		return $files;
	}

	/**
	 * @param string           $pattern
	 * @param CM_Site_Abstract $site
	 * @return string[]
	 */
	public static function rglobLibraries($pattern, CM_Site_Abstract $site) {
		$paths = array();
		foreach ($site->getNamespaces() as $namespace) {
			$libraryPath = CM_Util::getNamespacePath($namespace) . 'library/' . $namespace . '/';
			$paths = array_merge($paths, CM_Util::rglob($pattern, $libraryPath));
		}
		return $paths;
	}

	/**
	 * @param array $array
	 * @param mixed $value
	 * @return array
	 */
	public static function array_remove(array $array, $value) {
		return array_filter($array, function ($entry) use ($value) {
			return $value != $entry;
		});
	}

	/**
	 * @param string       $className
	 * @param boolean|null $ignoreInvalid
	 * @throws CM_Exception_Invalid
	 * @return string
	 */
	public static function getNamespace($className, $ignoreInvalid = null) {
		if (null === $ignoreInvalid) {
			$ignoreInvalid = false;
		}
		$ignoreInvalid = (boolean) $ignoreInvalid;
		$className = (string) $className;
		$tail = strpbrk($className, '_\\');
		$namespace = substr($className, 0, -strlen($tail));
		if (!$namespace) {
			if ($ignoreInvalid) {
				return null;
			}
			throw new CM_Exception_Invalid('Could not detect namespace of `' . $className . '`.');
		}
		return $namespace;
	}

	/**
	 * @param string       $url
	 * @param array|null   $params
	 * @param boolean|null $methodPost
	 * @param int|null     $timeout
	 * @throws CM_Exception_Invalid
	 * @return string
	 */
	public static function getContents($url, array $params = null, $methodPost = null, $timeout = null) {
		$url = (string) $url;
		if (!empty($params)) {
			$params = http_build_query($params);
		}
		if (null === $timeout) {
			$timeout = 10;
		}
		$timeout = (int) $timeout;

		$curlConnection = curl_init();
		curl_setopt($curlConnection, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($curlConnection, CURLOPT_TIMEOUT, $timeout);
		if ($methodPost) {
			curl_setopt($curlConnection, CURLOPT_POST, 1);
			if (!empty($params)) {
				curl_setopt($curlConnection, CURLOPT_POSTFIELDS, $params);
			}
		} else {
			if (!empty($params)) {
				$url .= '?' . $params;
			}
		}
		curl_setopt($curlConnection, CURLOPT_URL, $url);

		$curlError = null;
		$contents = curl_exec($curlConnection);
		if ($contents === false) {
			$curlError = 'Fetching contents from `' . $url . '` failed: `' . curl_error($curlConnection) . '`';
		}

		$info = curl_getinfo($curlConnection);
		if ((int) $info['http_code'] !== 200) {
			$curlError = 'HTTP Code = `' . $info['http_code'] . '`';
		}

		curl_close($curlConnection);
		if ($curlError) {
			throw new CM_Exception_Invalid($curlError);
		}
		return $contents;
	}

	/**
	 * @param string $xml
	 * @throws CM_Exception_Invalid
	 * @return SimpleXMLElement
	 */
	public static function parseXml($xml) {
		$xml = (string) $xml;

		$xml = @simplexml_load_string($xml);
		if (false === $xml) {
			throw new CM_Exception_Invalid('Could not parse xml');
		}

		return $xml;
	}

	/**
	 * @param string $path
	 * @return string
	 * @throws CM_Exception
	 */
{'fraction_non_alphanumeric': 0.16620196387440903, 'fraction_numerical': 0.0029094435689174447, 'mean_word_length': 3.5580110497237567, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 20}, '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': '5068463', 'n_tokens_mistral': 3147, 'n_tokens_neox': 2745, 'n_words': 674}