<commit_before><?php

abstract class ActiveRecord extends Model
{
	const TIMESTAMP = 'timestamp';
	const UPLOAD = 'upload';
	const PASSWORD = 'password';
	const BELONGS_TO = 'belongsTo';
	const HAS_ONE = 'hasOne';
	const HAS_MANY = 'hasMany';
	const HAS_AND_BELONGS_TO_MANY = 'hasAndBelongsToMany';

	public static $models = array();
	public $tableName;
	public $sequenceName;
	public $order;
	private $new = false;
	private $modified = array();
	private $deleted = false;
	private $pk = null;
	private $attributes = array();
	private $relations = null;
	private $associations = array();
	private $collections = array();
	private $criteria = array();
	private $formatter;

	public static function model($class=__CLASS__) {
		if (!isset(self::$models[$class]))
			self::$models[$class] = new $class(null);
		else
			self::$models[$class]->resetScopes();
		return self::$models[$class];
	}

	public function __construct($scenario='insert') {
		parent::__construct();
		$this->registerEvents(array(
			'onLoad', 'onException',
			'onBeforeSave', 'onAfterSave',
			'onBeforeInsert', 'onAfterInsert',
			'onBeforeUpdate', 'onAfterUpdate',
			'onBeforeDelete', 'onAfterDelete'
		));
		$this->parseRelations();
		if ($scenario !== null) {
			$this->setScenario($scenario);
			$this->formatter = new ActiveRecordFormatter($this);
			$this->new = ($scenario == 'insert');
			$this->init();
		}
	}

	public function __destruct() {
		$this->formatter = null;
		foreach ($this->associations as $id => $obj) {
			if ($obj instanceof ActiveRecord)
				$obj->__destruct();
		}
		foreach ($this->collections as $id => $collection) {
			foreach ($collection as $obj)
				$obj->__destruct();
		}
		parent::__destruct();
	}

	public function init() {
		parent::init();
		if ($this->getScenario() == 'insert') {
			foreach ($this->getMetaData()->columns as $name => $column) {
				if ($column->default !== null) {
					if (isset($this->formatter->formats[$name]))
						$this->setAttribute($name, $this->formatter->formatGet($name, $column->default));
					else
						$this->setAttribute($name, $column->default);
				}
			}
		}
	}

	public function __get($name) {
		if (isset($this->attributes[$name]))
			return $this->getAttribute($name);
		elseif ($this->getMetaData()->hasColumn($name))
			return null;
		elseif (isset($this->relations[$name]))
			return $this->getRelation($name);
		elseif (property_exists($this, $name) && isset($this->formatter->formats[$name]))
			return $this->formatter->formatGet($name);
		return parent::__get($name);
	}

	public function __set($name, $value) {
		if (!$this->setAttribute($name, $value)) {
			if (isset($this->relations[$name]))
				$this->setRelation($name, $value);
			else
				parent::__set($name, $value);
		}
	}

	public function __isset($name) {
		if (isset($this->attributes[$name]))
			return true;
		elseif ($this->getMetaData()->hasColumn($name))
			return false;
		elseif (array_key_exists($name, $this->associations))
			return (!empty($this->associations[$name]));
		elseif (array_key_exists($name, $this->collections))
			return (!empty($this->collections[$name]));
		elseif (isset($this->relations[$name])) {
			$relation = $this->getRelation($name);
			return (!empty($relation));<commit_msg>Missing second argument to ActiveRecordFormatter->formatGet<commit_after><?php

abstract class ActiveRecord extends Model
{
	const TIMESTAMP = 'timestamp';
	const UPLOAD = 'upload';
	const PASSWORD = 'password';
	const BELONGS_TO = 'belongsTo';
	const HAS_ONE = 'hasOne';
	const HAS_MANY = 'hasMany';
	const HAS_AND_BELONGS_TO_MANY = 'hasAndBelongsToMany';

	public static $models = array();
	public $tableName;
	public $sequenceName;
	public $order;
	private $new = false;
	private $modified = array();
	private $deleted = false;
	private $pk = null;
	private $attributes = array();
	private $relations = null;
	private $associations = array();
	private $collections = array();
	private $criteria = array();
	private $formatter;

	public static function model($class=__CLASS__) {
		if (!isset(self::$models[$class]))
			self::$models[$class] = new $class(null);
		else
			self::$models[$class]->resetScopes();
		return self::$models[$class];
	}

	public function __construct($scenario='insert') {
		parent::__construct();
		$this->registerEvents(array(
			'onLoad', 'onException',
			'onBeforeSave', 'onAfterSave',
			'onBeforeInsert', 'onAfterInsert',
			'onBeforeUpdate', 'onAfterUpdate',
			'onBeforeDelete', 'onAfterDelete'
		));
		$this->parseRelations();
		if ($scenario !== null) {
			$this->setScenario($scenario);
			$this->formatter = new ActiveRecordFormatter($this);
			$this->new = ($scenario == 'insert');
			$this->init();
		}
	}

	public function __destruct() {
		$this->formatter = null;
		foreach ($this->associations as $id => $obj) {
			if ($obj instanceof ActiveRecord)
				$obj->__destruct();
		}
		foreach ($this->collections as $id => $collection) {
			foreach ($collection as $obj)
				$obj->__destruct();
		}
		parent::__destruct();
	}

	public function init() {
		parent::init();
		if ($this->getScenario() == 'insert') {
			foreach ($this->getMetaData()->columns as $name => $column) {
				if ($column->default !== null) {
					if (isset($this->formatter->formats[$name]))
						$this->setAttribute($name, $this->formatter->formatGet($name, $column->default));
					else
						$this->setAttribute($name, $column->default);
				}
			}
		}
	}

	public function __get($name) {
		if (isset($this->attributes[$name]))
			return $this->getAttribute($name);
		elseif ($this->getMetaData()->hasColumn($name))
			return null;
		elseif (isset($this->relations[$name]))
			return $this->getRelation($name);
		elseif (property_exists($this, $name) && isset($this->formatter->formats[$name]))
			return $this->formatter->formatGet($name, $this->{$name});
		return parent::__get($name);
	}

	public function __set($name, $value) {
		if (!$this->setAttribute($name, $value)) {
			if (isset($this->relations[$name]))
				$this->setRelation($name, $value);
			else
				parent::__set($name, $value);
		}
	}

	public function __isset($name) {
		if (isset($this->attributes[$name]))
			return true;
		elseif ($this->getMetaData()->hasColumn($name))
			return false;
		elseif (array_key_exists($name, $this->associations))
			return (!empty($this->associations[$name]));
		elseif (array_key_exists($name, $this->collections))
			return (!empty($this->collections[$name]));
		elseif (isset($this->relations[$name])) {
			$relation = $this->getRelation($name);
			return (!empty($relation));
{'fraction_non_alphanumeric': 0.18570116350275567, 'fraction_numerical': 0.0, 'mean_word_length': 4.853942652329749, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 103, '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': '4875077', 'n_tokens_mistral': 2344, 'n_tokens_neox': 2095, 'n_words': 442}