<commit_before><?php

namespace Neptune\File;

use Neptune\Exceptions\FileException;
use Neptune\Helpers\String;

/**
 * UploadHandler
 * @author <NAME> <<EMAIL>>
 */
class UploadHandler {

	protected $name;
	protected $filename;
	protected $extension;
	protected $location;
	protected $overwrite = false;
	protected $scramble_chars = String::ALPHANUM;
	protected $scramble_length = 16;

	public function __construct($name) {
		if (isset($_FILES[$name])) {
			$this->name = $name;
			$this->filename = $_FILES[$name]['name'];
			$this->location = $this->getDirectoryFromPath($_FILES[$name]['tmp_name']);
			$this->extension = $this->getExtensionFromPath($_FILES[$name]['name']);
		} else {
			throw new \Exception("Uploaded file not found: $name");
		}
	}

	protected function getFilenameFromPath($path) {
		return substr(strrchr($path, '/'), 1);
	}

	protected function getDirectoryFromPath($path) {
		return substr($path, 0, strrpos($path, '/') + 1);
	}

	protected function getExtensionFromPath($path) {
		return substr($path, strrpos($path, '.'));
	}

	public function getName() {
		return $this->name;
	}
<commit_msg>Adding error checking to UploadHandler.<commit_after><?php

namespace Neptune\File;

use Neptune\Exceptions\FileException;
use Neptune\Helpers\String;

/**
 * UploadHandler
 * @author <NAME> <<EMAIL>>
 */
class UploadHandler {

	protected $name;
	protected $filename;
	protected $extension;
	protected $location;
	protected $overwrite = false;
	protected $scramble_chars = String::ALPHANUM;
	protected $scramble_length = 16;

	public function __construct($name) {
		$this->checkErrors($name);
		$this->name = $name;
		$this->filename = $_FILES[$name]['name'];
		$this->location = $this->getDirectoryFromPath($_FILES[$name]['tmp_name']);
		$this->extension = $this->getExtensionFromPath($_FILES[$name]['name']);
	}

	protected function checkErrors($name) {
		$code = $_FILES[$name]['error'];
		if($code === UPLOAD_ERR_OK) {
			return true;
		}
		switch ($code) {
		case UPLOAD_ERR_INI_SIZE:
			throw new FileException("File exceeds the maximum file size.");
		case UPLOAD_ERR_FORM_SIZE:
			throw new FileException("File exceeds the maximum file size.");
		case UPLOAD_ERR_PARTIAL:
			throw new FileException("File was only partially uploaded.");
		case UPLOAD_ERR_NO_FILE:
			throw new FileException("No file submitted.");
		case UPLOAD_ERR_NO_TMP_DIR:
			throw new FileException("Unable to find temporary location for file.");
		case UPLOAD_ERR_CANT_WRITE:
			throw new FileException("Failed to write file $name to disk.");
		case UPLOAD_ERR_EXTENSION:
			throw new FileException("A PHP extension prevented the upload from succeeding.");
		default:
			throw new FileException("The upload failed.");
		}
	}

	protected function getFilenameFromPath($path) {
		return substr(strrchr($path, '/'), 1);
	}

	protected function getDirectoryFromPath($path) {
		return substr($path, 0, strrpos($path, '/') + 1);
	}

	protected function getExtensionFromPath($path) {
		return substr($path, strrpos($path, '.'));
	}

	public function getName() {
		return $this->name;
	}

{'fraction_non_alphanumeric': 0.14568462037637897, 'fraction_numerical': 0.003244646333549643, 'mean_word_length': 5.104950495049505, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 24, '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': '7569849', 'n_tokens_mistral': 1058, 'n_tokens_neox': 980, 'n_words': 234}