<commit_before><?php

namespace PeskyCMF\Db;

use Illuminate\Validation\PresenceVerifierInterface;
use PeskyCMF\Config\CmfConfig;

class DatabasePresenceVerifier implements PresenceVerifierInterface {

    /**
     * Count the number of objects in a collection having the given value.
     *
     * @param  string $tableName
     * @param  string $column
     * @param  string $value
     * @param  int $excludeId
     * @param  string $idColumn
     * @param  array $extra
     * @return int
     */
    public function getCount($tableName, $column, $value, $excludeId = null, $idColumn = null, array $extra = []) {
        $conditions = [$column => $value];
        if (!is_null($excludeId) && $excludeId != 'NULL') {
            $conditions[($idColumn ?: 'id') . ' !='] = $excludeId;
        }
        foreach ($extra as $key => $extraValue) {
            $this->addWhere($conditions, $key, $extraValue);
        }
        return $this->getModel($tableName)->count($conditions);
    }

    /**
     * Count the number of objects in a collection with the given values.
     *
     * @param  string $tableName
     * @param  string $column
     * @param  array $values
     * @param  array $extra
     * @return int
     */
    public function getMultiCount($tableName, $column, array $values, array $extra = []) {
        $conditions = [$column => $values];

        foreach ($extra as $key => $extraValue) {
            $this->addWhere($conditions, $key, $extraValue);
        }

        return $this->getModel($tableName)->count($conditions);
    }

    /**
     * @param $tableName
     * @return CmfDbModel
     * @throws \PeskyORM\Exception\DbUtilsException
     */
    private function getModel($tableName) {
        /** @var CmfDbModel $baseClass */
        $baseClass = app()->make('base_db_model_class');
        return $baseClass::getModelByClassName($baseClass::getFullModelClassByTableName($tableName));
    }

    /**
     * Add a "where" clause to the given query.
     *
     * @param  array $conditions
     * @param  string $key
     * @param  string $extraValue
     * @return void
     */
    protected function addWhere(&$conditions, $key, $extraValue) {
        if ($extraValue === 'NULL') {
            $conditions[$key] = null;
        } elseif ($extraValue === 'NOT_NULL') {
            $conditions[$key . '!='] = null;
        } else {
            $conditions[$key] = $extraValue;
        }
    }

}<commit_msg>DatabasePresenceVerifier - added setConnection() method to fix crash<commit_after><?php

namespace PeskyCMF\Db;

use Illuminate\Validation\PresenceVerifierInterface;
use PeskyCMF\Config\CmfConfig;

class DatabasePresenceVerifier implements PresenceVerifierInterface {

    /**
     * Count the number of objects in a collection having the given value.
     *
     * @param  string $tableName
     * @param  string $column
     * @param  string $value
     * @param  int $excludeId
     * @param  string $idColumn
     * @param  array $extra
     * @return int
     */
    public function getCount($tableName, $column, $value, $excludeId = null, $idColumn = null, array $extra = []) {
        $conditions = [$column => $value];
        if (!is_null($excludeId) && $excludeId != 'NULL') {
            $conditions[($idColumn ?: 'id') . ' !='] = $excludeId;
        }
        foreach ($extra as $key => $extraValue) {
            $this->addWhere($conditions, $key, $extraValue);
        }
        return $this->getModel($tableName)->count($conditions);
    }

    /**
     * Count the number of objects in a collection with the given values.
     *
     * @param  string $tableName
     * @param  string $column
     * @param  array $values
     * @param  array $extra
     * @return int
     */
    public function getMultiCount($tableName, $column, array $values, array $extra = []) {
        $conditions = [$column => $values];

        foreach ($extra as $key => $extraValue) {
            $this->addWhere($conditions, $key, $extraValue);
        }

        return $this->getModel($tableName)->count($conditions);
    }

    /**
     * @param $tableName
     * @return CmfDbModel
     * @throws \PeskyORM\Exception\DbUtilsException
     */
    private function getModel($tableName) {
        /** @var CmfDbModel $baseClass */
        $baseClass = app()->make('base_db_model_class');
        return $baseClass::getModelByClassName($baseClass::getFullModelClassByTableName($tableName));
    }

    /**
     * Add a "where" clause to the given query.
     *
     * @param  array $conditions
     * @param  string $key
     * @param  string $extraValue
     * @return void
     */
    protected function addWhere(&$conditions, $key, $extraValue) {
        if ($extraValue === 'NULL') {
            $conditions[$key] = null;
        } elseif ($extraValue === 'NOT_NULL') {
            $conditions[$key . '!='] = null;
        } else {
            $conditions[$key] = $extraValue;
        }
    }

    public function setConnection($connection) {
        // don't need this but may come
    }

}
{'fraction_non_alphanumeric': 0.13785557986870897, 'fraction_numerical': 0.0, 'mean_word_length': 2.439124487004104, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '7140630', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1461, 'n_words': 363}