<commit_before><?php

class CM_Session {

	const ACTIVITY_EXPIRATION = 240; // 4 mins

	/**
	 * @var CM_Session $_instance
	 */
	private static $_instance = null;

	/**
	 * @param string $key
	 * @return misc
	 */
	public function get($key) {
		if (!isset($_SESSION[$key])) {
			return null;
		}
		return $_SESSION[$key];
	}

	/**
	 * @param string $key
	 * @param misc   $data
	 */
	public function set($key, $data) {
		$_SESSION[$key] = $data;
	}

	/**
	 * @param string $key
	 * @return boolean
	 */
	public function has($key) {
		return isset($_SESSION[$key]);
	}

	/**
	 * @param bool $needed OPTIONAL Throw a CM_Exception_AuthRequired if not authenticated
	 * @return CM_Model_User Session-user OR null
	 */
	public function getViewer($needed = false) {
		if ($this->has('userId')) {
			try {
				return CM_Model_User::factory($this->get('userId'));
			} catch (CM_Exception_Nonexistent $ex) {
			}
		}
		if ($needed) {
			throw new CM_Exception_AuthRequired();
		}
		return null;
	}

	public function logout() {
		if ($user = $this->getViewer()) {
			$user->setOnline(false);
		}
		if (session_id()) {
			session_destroy();
			$this->start(true);
		}
	}

	public function login(CM_Model_User $user) {
		$this->start(true);
		$this->set('userId', $user->getId());
	}

	public function start($regenerateId = false) {
		CM_SessionHandler::register();
		if (!headers_sent()) {
			session_start();
			if ($regenerateId) {
				session_regenerate_id(true);
			}
		}

		if (CM_Request_Abstract::isIpBlocked()) {<commit_msg>t8: fixed infinite function nesting<commit_after><?php

class CM_Session {

	const ACTIVITY_EXPIRATION = 240; // 4 mins

	/**
	 * @var CM_Session $_instance
	 */
	private static $_instance = null;

	/**
	 * @param string $key
	 * @return misc
	 */
	public function get($key) {
		if (!isset($_SESSION[$key])) {
			return null;
		}
		return $_SESSION[$key];
	}

	/**
	 * @param string $key
	 * @param misc   $data
	 */
	public function set($key, $data) {
		$_SESSION[$key] = $data;
	}

	/**
	 * @param string $key
	 * @return boolean
	 */
	public function has($key) {
		return isset($_SESSION[$key]);
	}

	/**
	 * @param bool $needed OPTIONAL Throw a CM_Exception_AuthRequired if not authenticated
	 * @return CM_Model_User Session-user OR null
	 */
	public function getViewer($needed = false) {
		if ($this->has('userId')) {
			try {
				return CM_Model_User::factory($this->get('userId'));
			} catch (CM_Exception_Nonexistent $ex) {
			}
		}
		if ($needed) {
			throw new CM_Exception_AuthRequired();
		}
		return null;
	}

	public function logout() {
		if ($user = $this->getViewer()) {
			$user->setOnline(false);
		}
		if (session_id()) {
			session_destroy();
			session_regenerate_id();
		}
	}

	public function login(CM_Model_User $user) {
		$this->start(true);
		$this->set('userId', $user->getId());
	}

	public function start($regenerateId = false) {
		CM_SessionHandler::register();
		if (!headers_sent()) {
			session_start();
			if ($regenerateId) {
				session_regenerate_id(true);
			}
		}

		if (CM_Request_Abstract::isIpBlocked()) {
{'fraction_non_alphanumeric': 0.16346466948876587, 'fraction_numerical': 0.002930641484858352, 'mean_word_length': 3.5309734513274336, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 18, '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': '883627', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1052, 'n_words': 236}