<commit_before><?php
/**
 * Fuel
 *
 * Fuel is a fast, lightweight, community driven PHP5 framework.
 *
 * @package		Fuel
 * @version		1.0
 * @author		Fuel Development Team
 * @license		MIT License
 * @copyright	2010 <NAME>
 * @link		http://fuelphp.com
 */

namespace Fuel;

class Error {

	public static $levels = array(
		E_ERROR				=>	'Error',
		E_WARNING			=>	'Warning',
		E_PARSE				=>	'Parsing Error',
		E_NOTICE			=>	'Notice',
		E_CORE_ERROR		=>	'Core Error',
		E_CORE_WARNING		=>	'Core Warning',
		E_COMPILE_ERROR		=>	'Compile Error',
		E_COMPILE_WARNING	=>	'Compile Warning',
		E_USER_ERROR		=>	'User Error',
		E_USER_WARNING		=>	'User Warning',
		E_USER_NOTICE		=>	'User Notice',
		E_STRICT			=>	'Runtime Notice'
	);

	public static $fatal_levels = array(E_PARSE, E_ERROR, E_USER_ERROR, E_COMPILE_ERROR);

	public static $count = 0;

	/**
	 * Native PHP shutdown handler
	 *
	 * @access	private
	 * @param	object	the exception object
	 * @return	string
	 */
	public static function shutdown_handler()
	{
		$last_error = error_get_last();

		// Only show valid fatal errors
		if ($last_error AND in_array($last_error['type'], static::$fatal_levels))
		{
			$severity = static::$levels[$last_error['type']];
			Log::error($severity.' - '.$last_error['message'].' in '.$last_error['file'].' on line '.$last_error['line']);

			static::show_php_error(new \ErrorException($last_error['message'], $last_error['type'], 0, $last_error['file'], $last_error['line']));

			exit(1);
		}
	}

	public static function exception_handler(\Exception $e)
	{
		$severity = ( ! isset(static::$levels[$e->getCode()])) ? $e->getCode() : static::$levels[$e->getCode()];
		Log::error($severity.' - '.$e->getMessage().' in '.$e->getFile().' on line '.$e->getLine());

		static::show_php_error($e);
	}

	public static function error_handler($severity, $message, $filepath, $line)
	{
		if (static::$count <= Config::get('error_throttling', 10))
		{
			Log::error($severity.' - '.$message.' in '.$filepath.' on line '.$line);
	
			if (($severity & error_reporting()) == $severity)
			{
				static::$count++;
				static::show_php_error(new \ErrorException($message, $severity, 0, $filepath, $line));
			}
		}
		elseif (static::$count == (Config::get('error_throttling', 10) + 1)
				&& ($severity & error_reporting()) == $severity)
		{
			static::$count++;
			static::notice('Error throttling threshold was reached, no more full error reports are shown.');
		}

		return true;
	}

	public static function show_php_error(\Exception $e)
	{
		$data['type']		= get_class($e);
		$data['severity']	= $e->getCode();
		$data['message']	= $e->getMessage();
		$data['filepath']	= $e->getFile();
		$data['error_line']	= $e->getLine();
		$data['backtrace']	= $e->getTrace();

		array_shift($data['backtrace']);

		foreach ($data['backtrace'] as $key => $trace)
		{
			if ( ! isset($trace['file']))
			{
				unset($data['backtrace'][$key]);
			}
			elseif (strncmp($trace['file'], APPPATH, strlen(APPPATH)) !== 0)
			{
				unset($data['backtrace'][$key]);
			}
		}

		$data['severity'] = ( ! isset(static::$levels[$data['severity']])) ? $data['severity'] : static::$levels[$data['severity']];

		$data['debug_lines'] = Debug::file_lines($data['filepath'], $data['error_line']);

		$data['filepath'] = Fuel::clean_path($data['filepath']);

		$data['filepath'] = str_replace("\\", "/", $data['filepath']);

		echo View::factory('errors'.DS.'php_error', $data);
	}

	public static function notice($msg)
	{
		if (Fuel::$env == Env::PRODUCTION || Config::get('show_notices', true) === false)
		{
			return;
		}

		$trace = Arr::element(debug_backtrace(), 1);

		Log::debug('Notice - '.$msg.' in '.$trace['file'].' on line '.$trace['line']);

		$data['message']	= $msg;
		$data['type']		= 'Notice';
		$data['filepath']	= str_replace("\\", "/", Fuel::clean_path($trace['file']));
		$data['line']		= $trace['line'];
		$data['function']	= $trace['function'];

		echo View::factory('errors'.DS.'php_short', $data);
	}

}

/* End of file error.php */<commit_msg>Added "always show" param to Error::notice(), which makes it show even in PRODUCTION or when notices are switched off. Should be used with care!<commit_after><?php
/**
 * Fuel
 *
 * Fuel is a fast, lightweight, community driven PHP5 framework.
 *
 * @package		Fuel
 * @version		1.0
 * @author		Fuel Development Team
 * @license		MIT License
 * @copyright	2010 <NAME>
 * @link		http://fuelphp.com
 */

namespace Fuel;

class Error {

	public static $levels = array(
		E_ERROR				=>	'Error',
		E_WARNING			=>	'Warning',
		E_PARSE				=>	'Parsing Error',
		E_NOTICE			=>	'Notice',
		E_CORE_ERROR		=>	'Core Error',
		E_CORE_WARNING		=>	'Core Warning',
		E_COMPILE_ERROR		=>	'Compile Error',
		E_COMPILE_WARNING	=>	'Compile Warning',
		E_USER_ERROR		=>	'User Error',
		E_USER_WARNING		=>	'User Warning',
		E_USER_NOTICE		=>	'User Notice',
		E_STRICT			=>	'Runtime Notice'
	);

	public static $fatal_levels = array(E_PARSE, E_ERROR, E_USER_ERROR, E_COMPILE_ERROR);

	public static $count = 0;

	/**
	 * Native PHP shutdown handler
	 *
	 * @access	private
	 * @param	object	the exception object
	 * @return	string
	 */
	public static function shutdown_handler()
	{
		$last_error = error_get_last();

		// Only show valid fatal errors
		if ($last_error AND in_array($last_error['type'], static::$fatal_levels))
		{
			$severity = static::$levels[$last_error['type']];
			Log::error($severity.' - '.$last_error['message'].' in '.$last_error['file'].' on line '.$last_error['line']);

			static::show_php_error(new \ErrorException($last_error['message'], $last_error['type'], 0, $last_error['file'], $last_error['line']));

			exit(1);
		}
	}

	public static function exception_handler(\Exception $e)
	{
		$severity = ( ! isset(static::$levels[$e->getCode()])) ? $e->getCode() : static::$levels[$e->getCode()];
		Log::error($severity.' - '.$e->getMessage().' in '.$e->getFile().' on line '.$e->getLine());

		static::show_php_error($e);
	}

	public static function error_handler($severity, $message, $filepath, $line)
	{
		if (static::$count <= Config::get('error_throttling', 10))
		{
			Log::error($severity.' - '.$message.' in '.$filepath.' on line '.$line);
	
			if (($severity & error_reporting()) == $severity)
			{
				static::$count++;
				static::show_php_error(new \ErrorException($message, $severity, 0, $filepath, $line));
			}
		}
		elseif (static::$count == (Config::get('error_throttling', 10) + 1)
				&& ($severity & error_reporting()) == $severity)
		{
			static::$count++;
			static::notice('Error throttling threshold was reached, no more full error reports are shown.', true);
		}

		return true;
	}

	public static function show_php_error(\Exception $e)
	{
		$data['type']		= get_class($e);
		$data['severity']	= $e->getCode();
		$data['message']	= $e->getMessage();
		$data['filepath']	= $e->getFile();
		$data['error_line']	= $e->getLine();
		$data['backtrace']	= $e->getTrace();

		array_shift($data['backtrace']);

		foreach ($data['backtrace'] as $key => $trace)
		{
			if ( ! isset($trace['file']))
			{
				unset($data['backtrace'][$key]);
			}
			elseif (strncmp($trace['file'], APPPATH, strlen(APPPATH)) !== 0)
			{
				unset($data['backtrace'][$key]);
			}
		}

		$data['severity'] = ( ! isset(static::$levels[$data['severity']])) ? $data['severity'] : static::$levels[$data['severity']];

		$data['debug_lines'] = Debug::file_lines($data['filepath'], $data['error_line']);

		$data['filepath'] = Fuel::clean_path($data['filepath']);

		$data['filepath'] = str_replace("\\", "/", $data['filepath']);

		echo View::factory('errors'.DS.'php_error', $data);
	}

	public static function notice($msg, $always_show = false)
	{
		if ( ! $always_show && (Fuel::$env == Env::PRODUCTION || Config::get('show_notices', true) === false))
		{
			return;
		}

		$trace = Arr::element(debug_backtrace(), 1);

		Log::debug('Notice - '.$msg.' in '.$trace['file'].' on line '.$trace['line']);

		$data['message']	= $msg;
		$data['type']		= 'Notice';
		$data['filepath']	= str_replace("\\", "/", Fuel::clean_path($trace['file']));
		$data['line']		= $trace['line'];
		$data['function']	= $trace['function'];

		echo View::factory('errors'.DS.'php_short', $data);
	}

}

/* End of file error.php */
{'fraction_non_alphanumeric': 0.2120954003407155, 'fraction_numerical': 0.004380627889997567, 'mean_word_length': 4.468396540252828, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2208861', 'n_tokens_mistral': 3294, 'n_tokens_neox': 2938, 'n_words': 585}