<commit_before><?php

include_once "ImageJPEGRenderer.php";
include_once "ImagePNGRenderer.php";
include_once "io/ImageCache.php";

class ImageHandler {

	private $imageRenderer;
	private $settings;

	public function __construct(string $mimeType, Settings $settings) {
		$this->settings = $settings;

		switch($mimeType) {
			case "image/jpeg":
				$this->imageRenderer = new ImageJPEGRenderer();
				break;
			case "image/png":
				$this->imageRenderer = new ImagePNGRenderer();
				break;
		}
	}

	public function resizeImage(string $path, int $size, int $orientation) {
		if(!$this->imageRenderer) return;

		$cachedImgPath = NULL;
		$cache = NULL;
		$cachedImgName = $size.'_'.basename($path);

		if(!empty($this->settings->cacheFolder)) {
			$cache = new ImageCache(dirname($path).'/'.$this->settings->cacheFolder);
			if(!$cache->prepareCache()) return;

			if($cache->inCache($cachedImgName)) {
				$imagestat = stat($path);
				$cachestat = stat(dirname($path).'/'.$this->settings->cacheFolder.'/'.$cachedImgName);

				if($imagestat['mtime'] < $cachestat['mtime']) {
					$cache->getFromCache($cachedImgName);
					return;
				}

				//If we are here, original image mtime was newer than cached image mtime
				//Invalidate stale cache
				$cache->invalidateImage('*_'.basename($path));
			}
<commit_msg>Use content types from appropriate class instead of string constants<commit_after><?php

include_once "ImageJPEGRenderer.php";
include_once "ImagePNGRenderer.php";
include_once "io/ImageCache.php";
include_once "net/ContentType.php";

class ImageHandler {

	private $imageRenderer;
	private $settings;

	public function __construct(string $mimeType, Settings $settings) {
	public function __construct(string $mimeType, Settings $settings) {
		$this->settings = $settings;

		switch($mimeType) {
			case ContentType::JPEG:
				$this->imageRenderer = new ImageJPEGRenderer();
				break;
			case ContentType::PNG:
				$this->imageRenderer = new ImagePNGRenderer();
				break;
		}
	}

	public function resizeImage(string $path, int $size, int $orientation) {
		if(!$this->imageRenderer) return;

		$cachedImgPath = NULL;
		$cache = NULL;
		$cachedImgName = $size.'_'.basename($path);

		if(!empty($this->settings->cacheFolder)) {
			$cache = new ImageCache(dirname($path).'/'.$this->settings->cacheFolder);
			if(!$cache->prepareCache()) return;

			if($cache->inCache($cachedImgName)) {
				$imagestat = stat($path);
				$cachestat = stat(dirname($path).'/'.$this->settings->cacheFolder.'/'.$cachedImgName);

				if($imagestat['mtime'] < $cachestat['mtime']) {
					$cache->getFromCache($cachedImgName);
					return;
				}

				//If we are here, original image mtime was newer than cached image mtime
				//Invalidate stale cache
				$cache->invalidateImage('*_'.basename($path));
			}

{'fraction_non_alphanumeric': 0.157725321888412, 'fraction_numerical': 0.0, 'mean_word_length': 4.527667984189724, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 31, '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': '4592057', 'n_tokens_mistral': 1017, 'n_tokens_neox': 872, 'n_words': 181}