<commit_before><?php

namespace Bank\DataStore;

use Bank\DataStore\Traits\MapperTrait;
use Bank\DataStore\Traits\ModelTrait;
use Bank\Query\Delete;
use Bank\Query\Select;

/**
 * Class ActiveRecord
 * @package Bank\DataStore
 */
abstract class ActiveRecord implements ActiveRecordInterface, ModelInterface
{
    use MapperTrait, ModelTrait;

    /**
     * ActiveRecord constructor.
     * @param AdapterInterface|null $adapter
     */
    public function __construct(AdapterInterface $adapter = null)
    {
        if ($adapter) {
            $this->injectionAdapter($adapter);
        }
        self::injectionSchema();
    }

    /**
     * @throws \Exception
     */
    public function injectionAdapter(AdapterInterface $adapter)
    {
        $this->adapter = $adapter;
        $this->repo = $this->adapter->getRepo();

        return $this;
    }

    /**
     * @return int
     */
    public function save(): int
    {
        if ($this->getPrimaryKey()) {
            return $this->update($this);
        }

        $res = $this->insert($this);
        $id = $this->getConnection()->lastInsertId();
        $this->{$this->getPrimaryCol()} = $id;

        return $res;
    }

    /**
     * @return int
     */
    public function delete(): int
    {
        if (!$this->getPrimaryKey()) {
            return 0;<commit_msg>Fix Avoid variables with short names like $id.<commit_after><?php

namespace Bank\DataStore;

use Bank\DataStore\Traits\MapperTrait;
use Bank\DataStore\Traits\ModelTrait;
use Bank\Query\Delete;
use Bank\Query\Select;

/**
 * Class ActiveRecord
 * @package Bank\DataStore
 */
abstract class ActiveRecord implements ActiveRecordInterface, ModelInterface
{
    use MapperTrait, ModelTrait;

    /**
     * ActiveRecord constructor.
     * @param AdapterInterface|null $adapter
     */
    public function __construct(AdapterInterface $adapter = null)
    {
        if ($adapter) {
            $this->injectionAdapter($adapter);
        }
        self::injectionSchema();
    }

    /**
     * @throws \Exception
     */
    public function injectionAdapter(AdapterInterface $adapter)
    {
        $this->adapter = $adapter;
        $this->repo = $this->adapter->getRepo();

        return $this;
    }

    /**
     * @return int
     */
    public function save(): int
    {
        if ($this->getPrimaryKey()) {
            return $this->update($this);
        }

        $res = $this->insert($this);
        $lastInsertId = $this->getConnection()->lastInsertId();
        $this->{$this->getPrimaryCol()} = $lastInsertId;

        return $res;
    }

    /**
     * @return int
     */
    public function delete(): int
    {
        if (!$this->getPrimaryKey()) {
            return 0;
{'fraction_non_alphanumeric': 0.137550570062523, 'fraction_numerical': 0.000735564545788893, 'mean_word_length': 2.2653061224489797, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '7295835', 'n_tokens_mistral': 785, 'n_tokens_neox': 771, 'n_words': 162}