<commit_before><?php
use Airbrake\Configuration as AirbrakeConfiguration;
use Airbrake\Client as AirbrakeClient;
use Airbrake\Notice as AirbrakeNotice;

App::uses('Router', 'Routing');

class AirbrakeError extends ErrorHandler
{

	/**
	 * Creates a new Airbrake instance, or returns an instance created earlier.
	 * You can pass options to Airbrake\Configuration by setting the AirbrakeCake.options
	 * configuration property.
	 *
	 * For example to set the environment name:
	 *
	 * ```
	 * Configure::write('AirbrakeCake.options', array(
	 * 	'environmentName' => 'staging'
	 * ));
	 * ```
	 *
	 * @return Airbrake\Client
	 */
	public static function getAirbrake() {
		static $client = null;

		if ($client === null) {
			$apiKey  = Configure::read('AirbrakeCake.apiKey');
			$options = Configure::read('AirbrakeCake.options');

			if (!$options) {
				$options = array();
			}

			if (php_sapi_name() !== 'cli') {
				$request = Router::getRequest();

				if ($request) {
					$options['component'] = $request->params['controller';
					$options['action'] = $request->params['action'];
				}
			}

			$config = new AirbrakeConfiguration($apiKey, $options);
			$client = new AirbrakeClient($config);
		}

		return $client;
	}

	/**
	 * {@inheritDoc}
	 */
	public static function handleError($code, $description, $file = null, $line = null, $context = null) {
		list($error, $log) = self::mapErrorCode($code);

		$backtrace = debug_backtrace();
		if (count($backtrace) > 1) {
			array_shift($backtrace);
		}

		$notice = new AirbrakeNotice();
		$notice->load(array(
			'errorClass' => $error,
			'backtrace' => $backtrace,
			'errorMessage' => $description,<commit_msg>Added reporting of User id, if available<commit_after><?php
use Airbrake\Configuration as AirbrakeConfiguration;
use Airbrake\Client as AirbrakeClient;
use Airbrake\Notice as AirbrakeNotice;

App::uses('Router', 'Routing');

class AirbrakeError extends ErrorHandler
{

	/**
	 * Creates a new Airbrake instance, or returns an instance created earlier.
	 * You can pass options to Airbrake\Configuration by setting the AirbrakeCake.options
	 * configuration property.
	 *
	 * For example to set the environment name:
	 *
	 * ```
	 * Configure::write('AirbrakeCake.options', array(
	 * 	'environmentName' => 'staging'
	 * ));
	 * ```
	 *
	 * @return Airbrake\Client
	 */
	public static function getAirbrake() {
		static $client = null;

		if ($client === null) {
			$apiKey = Configure::read('AirbrakeCake.apiKey');
			$options = Configure::read('AirbrakeCake.options');

			if (!$options) {
				$options = array();
			}

			if (php_sapi_name() !== 'cli') {
				$request = Router::getRequest();

				if ($request) {
					$options['component'] = $request->params['controller'];
					$options['action'] = $request->params['action'];
				}

				if (!empty($_SESSION)) {
					$options['extraParameters'] = Hash::get($options, 'extraParameters', array());
					$options['extraParameters']['User']['id'] = Hash::get($_SESSION, 'Auth.User.id');
				}
			}

			$config = new AirbrakeConfiguration($apiKey, $options);
			$client = new AirbrakeClient($config);
		}

		return $client;
	}

	/**
	 * {@inheritDoc}
	 */
	public static function handleError($code, $description, $file = null, $line = null, $context = null) {
		list($error, $log) = self::mapErrorCode($code);

		$backtrace = debug_backtrace();
		if (count($backtrace) > 1) {
			array_shift($backtrace);
		}

		$notice = new AirbrakeNotice();
		$notice->load(array(
			'errorClass' => $error,
			'backtrace' => $backtrace,
			'errorMessage' => $description,
{'fraction_non_alphanumeric': 0.1625629546726357, 'fraction_numerical': 0.0005595970900951316, 'mean_word_length': 4.092592592592593, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '2185552', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1127, 'n_words': 262}