<commit_before><?php
/* ===========================================================================
 * Opis Project
 * http://opis.io
 * ===========================================================================
 * Copyright 2013-2015 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============================================================================ */

namespace Opis\Database;

use RuntimeException;
use Opis\Database\ORM\Query;
use Opis\Database\ORM\Relation\HasOne;
use Opis\Database\ORM\Relation\HasMany;
use Opis\Database\ORM\Relation\BelongsTo;
use Opis\Database\ORM\Relation\BelongsToMany;

abstract class Model implements ModelInterface
{
    /**
     * Autoincrement primary key type
     *
     * @var int
     */
    
    const PRIMARY_KEY_AUTOINCREMENT = 1;
    
    /**
     * Custom primary key type
     *
     * @var int
     */
    
    const PRIMARY_KEY_CUSTOM = 2;
    
    /**
     * Model's table name
     *
     * @var string
     */
    
    protected $table;
    
    /**
     * Table's primary key
     *
     * @var string
     */
    
    protected $primaryKey = 'id';
    
    /**
     * Primary key's type
     *
     * @var int
     */
    
    protected $primaryKeyType = Model::PRIMARY_KEY_AUTOINCREMENT;
    
    /**
     * Table's associated sequence name
     *
     * @var string
     */
    
    protected $sequence;
    
    /**
     * Guarded attributes that are not mass assignable
     *
     * @var array
     */
    
    protected $guarded;
    
    /**
     * Mass asignable attributes
     *
     * @var array
     */
    
    protected $fillable;
    
    /**
     * Database instance
     *
     * @var \Opis\Database\Database
     */
    protected $database;
    
    /**
     * Model's short class name
     *
     * @var string
     */
    
    protected $className;
    
    /**
     * Indicates if the record is loaded
     *
     * @var boolean
     */
    
    protected $loaded = false;
    
    /**
     * Indicates if the record was deleted
     *
     * @var boolean
     */
    
    protected $deleted = false;
    
    /**
     * Indicates if the model's properties are readonly
     *
     * @var boolean
     */
    
    protected $readonly = false;
    
    /**
     * A list with related models
     *
     * @var array
     */
    
    protected $result = array();
    
    /**
     * A list with loaders
     *
     * @var array
     */
    
    protected $loader = array();
    
    /**
     * Columns' values
     *
     * @var array
     */
    
    protected $columns = array();
    
    /**
     * A list with modified columns
     *
     * @var array
     */
    
    protected $modified = array();
    
    /**
     * A list of user defined column mappings
     */
    
    protected $mapColumns = array();
    
    /**
     * Internally used column mappings
     */
    
    protected $mapGetSet = array();
    
    /**
     * A list of user defined type casts for columns
     *
     * @var array
     */
    
    protected $cast = array();
    
    /**
     * Date format
     *
     * @var string
     */
    
    protected $dateFormat;
    
    /**
     * Database connection
     *
     * @var \Opis\Database\Connection
     */
    
    protected $dbcon;
    
    
    /**
     * Constructor
     *
     * @final
     * @access public
     *
     * @param   boolean $readonly   Indicates if this is a read-only model
     */
    
    public final function __construct($readonly = false, Connection $connection = null)
    {
        $this->loaded = true;
        $this->dbcon = $connection;
        $this->readonly = $readonly;
        $this->mapGetSet = array_flip($this->mapColumns);
    }
    
    /**
     * Creates a new record
     *
     * @param   array                       $columns    A column-value mapped array
     * @param   \Opis\Database\Connection   $connection (optional) Database connection
     *
     * @return  \Opis\Database\Model
     */
    
    public static function create(array $columns, Connection $connection = null)
    {
        if($connection === null)
        {
            $connection = static::getConnection();
        }
        
        $item = new static(false, $connection);
        $item->assign($columns);
        $item->save();
        return $item;
    }
    
    /**
     * Returns an instance of a model that use the given connection
     *
     * @param   \Opis\Database\Connection   $connection Database connection
     * @param   boolean                     $readonly   (optional) Read-only model
     *
     * @return  \Opis\Database\Model
     */
    
    public static function using(Connection $connection, $readonly = false)
    {
        return new static($readonly, $connection);
    }
    
    /**
     * Sets a columns value
     *
     * @param   string  $name   Column's name
     * @param   mixed   $value  Column's value
     */
    
    public function __set($name, $value)
    {   
        if(!$this->loaded)
        {
            $this->columns[$name] = $value;
            return;
        }<commit_msg>Removed unnecessary argument<commit_after><?php
/* ===========================================================================
 * Opis Project
 * http://opis.io
 * ===========================================================================
 * Copyright 2013-2015 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============================================================================ */

namespace Opis\Database;

use RuntimeException;
use Opis\Database\ORM\Query;
use Opis\Database\ORM\Relation\HasOne;
use Opis\Database\ORM\Relation\HasMany;
use Opis\Database\ORM\Relation\BelongsTo;
use Opis\Database\ORM\Relation\BelongsToMany;

abstract class Model implements ModelInterface
{
    /**
     * Autoincrement primary key type
     *
     * @var int
     */
    
    const PRIMARY_KEY_AUTOINCREMENT = 1;
    
    /**
     * Custom primary key type
     *
     * @var int
     */
    
    const PRIMARY_KEY_CUSTOM = 2;
    
    /**
     * Model's table name
     *
     * @var string
     */
    
    protected $table;
    
    /**
     * Table's primary key
     *
     * @var string
     */
    
    protected $primaryKey = 'id';
    
    /**
     * Primary key's type
     *
     * @var int
     */
    
    protected $primaryKeyType = Model::PRIMARY_KEY_AUTOINCREMENT;
    
    /**
     * Table's associated sequence name
     *
     * @var string
     */
    
    protected $sequence;
    
    /**
     * Guarded attributes that are not mass assignable
     *
     * @var array
     */
    
    protected $guarded;
    
    /**
     * Mass asignable attributes
     *
     * @var array
     */
    
    protected $fillable;
    
    /**
     * Database instance
     *
     * @var \Opis\Database\Database
     */
    protected $database;
    
    /**
     * Model's short class name
     *
     * @var string
     */
    
    protected $className;
    
    /**
     * Indicates if the record is loaded
     *
     * @var boolean
     */
    
    protected $loaded = false;
    
    /**
     * Indicates if the record was deleted
     *
     * @var boolean
     */
    
    protected $deleted = false;
    
    /**
     * Indicates if the model's properties are readonly
     *
     * @var boolean
     */
    
    protected $readonly = false;
    
    /**
     * A list with related models
     *
     * @var array
     */
    
    protected $result = array();
    
    /**
     * A list with loaders
     *
     * @var array
     */
    
    protected $loader = array();
    
    /**
     * Columns' values
     *
     * @var array
     */
    
    protected $columns = array();
    
    /**
     * A list with modified columns
     *
     * @var array
     */
    
    protected $modified = array();
    
    /**
     * A list of user defined column mappings
     */
    
    protected $mapColumns = array();
    
    /**
     * Internally used column mappings
     */
    
    protected $mapGetSet = array();
    
    /**
     * A list of user defined type casts for columns
     *
     * @var array
     */
    
    protected $cast = array();
    
    /**
     * Date format
     *
     * @var string
     */
    
    protected $dateFormat;
    
    /**
     * Database connection
     *
     * @var \Opis\Database\Connection
     */
    
    protected $dbcon;
    
    
    /**
     * Constructor
     *
     * @final
     * @access public
     *
     * @param   boolean $readonly   Indicates if this is a read-only model
     */
    
    public final function __construct($readonly = false, Connection $connection = null)
    {
        $this->loaded = true;
        $this->dbcon = $connection;
        $this->readonly = $readonly;
        $this->mapGetSet = array_flip($this->mapColumns);
    }
    
    /**
     * Creates a new record
     *
     * @param   array                       $columns    A column-value mapped array
     * @param   \Opis\Database\Connection   $connection (optional) Database connection
     *
     * @return  \Opis\Database\Model
     */
    
    public static function create(array $columns, Connection $connection = null)
    {
        if($connection === null)
        {
            $connection = static::getConnection();
        }
        
        $item = new static(false, $connection);
        $item->assign($columns);
        $item->save();
        return $item;
    }
    
    /**
     * Returns an instance of a model that use the given connection
     *
     * @param   \Opis\Database\Connection   $connection Database connection
     *
     * @return  \Opis\Database\Model
     */
    
    public static function using(Connection $connection)
    {
        return new static(false, $connection);
    }
    
    /**
     * Sets a columns value
     *
     * @param   string  $name   Column's name
     * @param   mixed   $value  Column's value
     */
    
    public function __set($name, $value)
    {   
        if(!$this->loaded)
        {
            $this->columns[$name] = $value;
            return;
        }
{'fraction_non_alphanumeric': 0.14186319689165988, 'fraction_numerical': 0.002530044275774826, 'mean_word_length': 1.7294697903822442, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '860427', 'n_tokens_mistral': 3173, 'n_tokens_neox': 3083, 'n_words': 842}