<commit_before><?php

namespace Bkwld\Decoy\Models;

use DB;
use Decoy;
use Config;
use DecoyURL;
use Illuminate\Support\Str;
use Bkwld\Decoy\Input\Search;
use Bkwld\Library\Utils\Text;
use Illuminate\Database\Eloquent\Model;

/**
 * Reperesents a single model change event.  Typically a single CRUD action on
 * a model.
 */
class Change extends Base
{
    /**
     * The query param key used when previewing
     *
     * @var string
     */
    const QUERY_KEY = 'view-change';

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'changed' => 'array',
    ];

    /**
     * Get the admin associated with the change
     *
     * @return Illuminate\Database\Eloquent\Relations\Relation
     */
    public function admin()
    {
        return $this->belongsTo('Bkwld\Decoy\Models\Admin');
    }

    /**
     * The polymorphic relation back to the parent model
     *
     * @var mixed
     */
    public function loggable()
    {
        return $this->morphTo('loggable', 'model', 'key');
    }

    /**
     * Get the related model, including trashed instances
     *
     * @return Model
     */
    public function changedModel()
    {
        return $this->loggable()->withTrashed();
    }

    /**
     * Default ordering by descending time, designed to be overridden
     *
     * @param  Illuminate\Database\Query\Builder $query
     * @return Illuminate\Database\Query\Builder
     */
    public function scopeOrdered($query)
    {
        return $query->orderBy('changes.id', 'desc')->with('admin');
    }

    /**
     * Check whether changes are enabled
     *
     * @return boolean
     */
    public static function enabled()
    {
        if ($check = Config::get('decoy.site.log_changes')) {
            if (is_bool($check)) {
                return $check;
            }

            if (is_callable($check)) {
                return call_user_func($check, $model, $action, app('decoy.user'));
            }
        }

        return false;
    }

    /**<commit_msg>Change::enabled() is cruft<commit_after><?php

namespace Bkwld\Decoy\Models;

use DB;
use Decoy;
use Config;
use DecoyURL;
use Illuminate\Support\Str;
use Bkwld\Decoy\Input\Search;
use Bkwld\Library\Utils\Text;
use Illuminate\Database\Eloquent\Model;

/**
 * Reperesents a single model change event.  Typically a single CRUD action on
 * a model.
 */
class Change extends Base
{
    /**
     * The query param key used when previewing
     *
     * @var string
     */
    const QUERY_KEY = 'view-change';

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'changed' => 'array',
    ];

    /**
     * Get the admin associated with the change
     *
     * @return Illuminate\Database\Eloquent\Relations\Relation
     */
    public function admin()
    {
        return $this->belongsTo('Bkwld\Decoy\Models\Admin');
    }

    /**
     * The polymorphic relation back to the parent model
     *
     * @var mixed
     */
    public function loggable()
    {
        return $this->morphTo('loggable', 'model', 'key');
    }

    /**
     * Get the related model, including trashed instances
     *
     * @return Model
     */
    public function changedModel()
    {
        return $this->loggable()->withTrashed();
    }

    /**
     * Default ordering by descending time, designed to be overridden
     *
     * @param  Illuminate\Database\Query\Builder $query
     * @return Illuminate\Database\Query\Builder
     */
    public function scopeOrdered($query)
    {
        return $query->orderBy('changes.id', 'desc')->with('admin');
    }

    /**
{'fraction_non_alphanumeric': 0.12311015118790497, 'fraction_numerical': 0.0, 'mean_word_length': 2.1239460370994943, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '4300127', 'n_tokens_mistral': 1131, 'n_tokens_neox': 1117, 'n_words': 287}