<commit_before><?php
namespace Exception;

use \HTTP\Response;
use \HTTP\Header\ContentType;
use \Psr\Http\Message\ResponseInterface;

abstract class BooBoo extends \Exception
{
	const BOOBOO = 1;
	const EXCEPTION = 2;
	const ERROR = 3;

	/**
	 * The logger object
	 * @var BooBoo\BooBooLog
	 */
	protected static $logger;

	/**
	 * HTTP response handler
	 * @var HTTP\Response
	 */
	protected static $httpHandler;

	/**
	 * Last action to be executed before the script ends
	 * @var bindToable
	 */
	protected static $lastAction;

	protected static $trace;

	protected static $vars = [];

	/**
	 * Error levels
	 * @var array
	 */
	protected static $levels = [
		E_ERROR				=>	'Fatal Error',
		E_WARNING			=>	'Warning',
		E_PARSE				=>	'Parsing Error',
		E_NOTICE			=>	'Notice',
		E_DEPRECATED 		=>	'Deprecated',
		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_USER_DEPRECATED 	=> 'User Deprecated',
		E_STRICT			=>	'Runtime Notice',
		E_RECOVERABLE_ERROR => 'Recoverable Error'
	];

	protected static $defaultErrorPath;

	protected static $ignore = [];

	protected static $alwaysLog = true;

	protected static $booboo;

	public function __construct($message = null, $code = 0, Exception $previous = null)
	{
		parent::__construct($message, $code, $previous);

		if (!isset(self::$httpHandler)) {
			self::setUp();
		}

		$this->buildObj();
	}

	protected function buildObj()
	{
		self::$booboo = new \StdClass;
		self::$booboo->tag = $this->getTag();
		self::$booboo->alwaysLog = true;
		self::$booboo->displayMessage = null;
		self::$booboo->logContext = [];
		self::$booboo->trace = false;
		self::$booboo->templateData = null;
		self::$booboo->httpHandler = (new Response())->withTypeNegotiation()->withStatus(500);
		self::$booboo->templates = array_merge(self::$defaultErrorPath, $this->getTemplates());
	}

	/**
	 * Get error tag that will appear in the error logs.
	 * Example: <tag>: Something went wrong
	 * @return String [Tag name]
	 */
	abstract protected function getTag();

	protected function getTemplates()
	{
		return [];
	}

	/**
	 * Set up BooBoo.
	 * @param \Psr\Log\LoggerInterface|null  $logger       A psr3 compatible logger
	 * @param \Closure                       $lastAction   Last action to run before script ends
	 * @param int                            $reportLevel  Level of reporting. One can pass a bitmask here
	 */
	final public static function setUp(\Psr\Log\LoggerInterface $logger = null, $traceAlwaysOn = false, \Closure $lastAction = null, $ignore = [])
	{
		ini_set('display_errors', 0);

		error_reporting(E_ALL - array_sum($ignore));

		self::$ignore = $ignore;

		self::$defaultErrorPath = [
			'text'	=>	__DIR__ . '/templates/text.php',
			'html'	=>	__DIR__ . '/templates/html.php',
			'json'	=>	__DIR__ . '/templates/json.php',
			'xml'	=>	__DIR__ . '/templates/xml.php'
		];

		self::$httpHandler = (new Response())->withTypeNegotiation()->withStatus(500);

		self::$logger = $logger;
		self::$trace = $traceAlwaysOn;
		self::$lastAction = $lastAction;

		set_exception_handler(['Exception\BooBoo','exceptionHandler']);
		set_error_handler(['Exception\BooBoo','errorHandler']);
		register_shutdown_function(['Exception\BooBoo','shutdownFunction']);
	}

	public function noLog()
	{
		self::$booboo->alwaysLog = false;

		return $this;
	}

	public function displayMessage($message)
	{
		self::$booboo->displayMessage = $message;

		return $this;
	}

	public function logContext($context)
	{
		self::$booboo->logContext = $context;

		return $this;
	}

	public function trace($turnOnTrace)
	{
		self::$booboo->trace = $turnOnTrace;

		return $this;
	}

	public function response(ResponseInterface $response)
	{
		self::$booboo->httpHandler = self::$booboo->httpHandler->withStatus(
			$response->getStatusCode() < 400 ? 500 : $response->getStatusCode()
		);

		foreach ($response->getHeaders() as $header => $value) {
			self::$booboo->httpHandler = self::$booboo->httpHandler->withHeader($header, implode(',', $value));
		}<commit_msg>method for setting status code<commit_after><?php
namespace Exception;

use \HTTP\Response;
use \HTTP\Header\ContentType;
use \Psr\Http\Message\ResponseInterface;

abstract class BooBoo extends \Exception
{
	const BOOBOO = 1;
	const EXCEPTION = 2;
	const ERROR = 3;

	/**
	 * The logger object
	 * @var BooBoo\BooBooLog
	 */
	protected static $logger;

	/**
	 * HTTP response handler
	 * @var HTTP\Response
	 */
	protected static $httpHandler;

	/**
	 * Last action to be executed before the script ends
	 * @var bindToable
	 */
	protected static $lastAction;

	protected static $trace;

	protected static $vars = [];

	/**
	 * Error levels
	 * @var array
	 */
	protected static $levels = [
		E_ERROR				=>	'Fatal Error',
		E_WARNING			=>	'Warning',
		E_PARSE				=>	'Parsing Error',
		E_NOTICE			=>	'Notice',
		E_DEPRECATED 		=>	'Deprecated',
		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_USER_DEPRECATED 	=> 'User Deprecated',
		E_STRICT			=>	'Runtime Notice',
		E_RECOVERABLE_ERROR => 'Recoverable Error'
	];

	protected static $defaultErrorPath;

	protected static $ignore = [];

	protected static $alwaysLog = true;

	protected static $booboo;

	public function __construct($message = null, $code = 0, Exception $previous = null)
	{
		parent::__construct($message, $code, $previous);

		if (!isset(self::$httpHandler)) {
			self::setUp();
		}

		$this->buildObj();
	}

	protected function buildObj()
	{
		self::$booboo = new \StdClass;
		self::$booboo->tag = $this->getTag();
		self::$booboo->alwaysLog = true;
		self::$booboo->displayMessage = null;
		self::$booboo->logContext = [];
		self::$booboo->trace = false;
		self::$booboo->templateData = null;
		self::$booboo->httpHandler = (new Response())->withTypeNegotiation()->withStatus(500);
		self::$booboo->templates = array_merge(self::$defaultErrorPath, $this->getTemplates());
	}

	/**
	 * Get error tag that will appear in the error logs.
	 * Example: <tag>: Something went wrong
	 * @return String [Tag name]
	 */
	abstract protected function getTag();

	protected function getTemplates()
	{
		return [];
	}

	/**
	 * Set up BooBoo.
	 * @param \Psr\Log\LoggerInterface|null  $logger       A psr3 compatible logger
	 * @param \Closure                       $lastAction   Last action to run before script ends
	 * @param int                            $reportLevel  Level of reporting. One can pass a bitmask here
	 */
	final public static function setUp(\Psr\Log\LoggerInterface $logger = null, $traceAlwaysOn = false, \Closure $lastAction = null, $ignore = [])
	{
		ini_set('display_errors', 0);

		error_reporting(E_ALL - array_sum($ignore));

		self::$ignore = $ignore;

		self::$defaultErrorPath = [
			'text'	=>	__DIR__ . '/templates/text.php',
			'html'	=>	__DIR__ . '/templates/html.php',
			'json'	=>	__DIR__ . '/templates/json.php',
			'xml'	=>	__DIR__ . '/templates/xml.php'
		];

		self::$httpHandler = (new Response())->withTypeNegotiation()->withStatus(500);

		self::$logger = $logger;
		self::$trace = $traceAlwaysOn;
		self::$lastAction = $lastAction;

		set_exception_handler(['Exception\BooBoo','exceptionHandler']);
		set_error_handler(['Exception\BooBoo','errorHandler']);
		register_shutdown_function(['Exception\BooBoo','shutdownFunction']);
	}

	public function noLog()
	{
		self::$booboo->alwaysLog = false;

		return $this;
	}

	public function displayMessage($message)
	{
		self::$booboo->displayMessage = $message;

		return $this;
	}

	public function logContext($context)
	{
		self::$booboo->logContext = $context;

		return $this;
	}

	public function trace($turnOnTrace)
	{
		self::$booboo->trace = $turnOnTrace;

		return $this;
	}

	public function status($code)
	{
		if ($code < 400) {
			throw new \InvalidArgumentException('Status code must be higuer or equal to 400');
		}

		self::$booboo->httpHandler->withStatus($code);

		return $this;
	}

	public function response(ResponseInterface $response)
	{
		self::$booboo->httpHandler = self::$booboo->httpHandler->withStatus(
			$response->getStatusCode() < 400 ? 500 : $response->getStatusCode()
		);

		foreach ($response->getHeaders() as $header => $value) {
			self::$booboo->httpHandler = self::$booboo->httpHandler->withHeader($header, implode(',', $value));
		}
{'fraction_non_alphanumeric': 0.15145540995013337, 'fraction_numerical': 0.004870694653832773, 'mean_word_length': 3.950631458094145, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 103, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '1249890', 'n_tokens_mistral': 3162, 'n_tokens_neox': 2885, 'n_words': 644}