<commit_before><?php namespace GeneaLabs\LaravelModelCaching;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Collection;

class CacheKey
{
    protected $eagerLoad;
    protected $model;
    protected $query;

    public function __construct(array $eagerLoad, Model $model, Builder $query)
    {
        $this->eagerLoad = $eagerLoad;
        $this->model = $model;
        $this->query = $query;
    }

    public function make(array $columns = ['*'], $idColumn = null) : string
    {
        $key = $this->getModelSlug();
        $key .= $this->getIdColumn($idColumn ?: '');
        $key .= $this->getQueryColumns($columns);
        $key .= $this->getWhereClauses();
        $key .= $this->getWithModels();
        $key .= $this->getOrderByClauses();
        $key .= $this->getOffsetClause();
        $key .= $this->getLimitClause();

        return $key;
    }

    protected function getIdColumn(string $idColumn) : string
    {
        return $idColumn ? "_{$idColumn}" : '';
    }

    protected function getLimitClause() : string
    {
        if (! $this->query->limit) {
            return '';
        }

        return "-limit_{$this->query->limit}";
    }

    protected function getModelSlug() : string
    {
        return str_slug(get_class($this->model));
    }

    protected function getOffsetClause() : string
    {
        if (! $this->query->offset) {
            return '';
        }

        return "-offset_{$this->query->offset}";
    }

    protected function getOrderByClauses() : string
    {
        $orders = collect($this->query->orders);

        return $orders
            ->reduce(function ($carry, $order) {
                if ($order['type'] === 'Raw') {
                    return $carry . '_orderByRaw_' . str_slug($order['sql']);
                }

                return $carry . '_orderBy_' . $order['column'] . '_' . $order['direction'];
            })
            ?: '';
    }

    protected function getQueryColumns(array $columns) : string<commit_msg>Fix inspection of `type` attribute<commit_after><?php namespace GeneaLabs\LaravelModelCaching;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Collection;

class CacheKey
{
    protected $eagerLoad;
    protected $model;
    protected $query;

    public function __construct(array $eagerLoad, Model $model, Builder $query)
    {
        $this->eagerLoad = $eagerLoad;
        $this->model = $model;
        $this->query = $query;
    }

    public function make(array $columns = ['*'], $idColumn = null) : string
    {
        $key = $this->getModelSlug();
        $key .= $this->getIdColumn($idColumn ?: '');
        $key .= $this->getQueryColumns($columns);
        $key .= $this->getWhereClauses();
        $key .= $this->getWithModels();
        $key .= $this->getOrderByClauses();
        $key .= $this->getOffsetClause();
        $key .= $this->getLimitClause();

        return $key;
    }

    protected function getIdColumn(string $idColumn) : string
    {
        return $idColumn ? "_{$idColumn}" : '';
    }

    protected function getLimitClause() : string
    {
        if (! $this->query->limit) {
            return '';
        }

        return "-limit_{$this->query->limit}";
    }

    protected function getModelSlug() : string
    {
        return str_slug(get_class($this->model));
    }

    protected function getOffsetClause() : string
    {
        if (! $this->query->offset) {
            return '';
        }

        return "-offset_{$this->query->offset}";
    }

    protected function getOrderByClauses() : string
    {
        $orders = collect($this->query->orders);

        return $orders
            ->reduce(function ($carry, $order) {
                if (($order['type'] ?? '') === 'Raw') {
                    return $carry . '_orderByRaw_' . str_slug($order['sql']);
                }

                return $carry . '_orderBy_' . $order['column'] . '_' . $order['direction'];
            })
            ?: '';
    }

    protected function getQueryColumns(array $columns) : string
{'fraction_non_alphanumeric': 0.15541031227305738, 'fraction_numerical': 0.0, 'mean_word_length': 2.1858134155744025, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, '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': '1826147', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1203, 'n_words': 235}