<commit_before><?php

namespace App\Traits;

trait Preferenceable
{
    public function preferences()
    {
        return $this->morphMany('App\Preference', 'preferenceable');
    }

    public function pref($key, $value = null, $type = 'string')
    {
        if (isset($value)) {
            $this->preferences()->updateOrCreate(['key' => $key], ['value' => $this->cast($value, $type), 'type' => $type]);
            return $value;
        }
        $default = \App\Preference::getDefault($this, $key);
        return($pref = $this->preferences()->forKey($key)->first()) ? $pref->value() : $default->value();
    }

    private function cast($value, $type)
    {
        switch ($type) {
            case 'bool':
                return boolval($value);
                break;
            case 'int':
                return intval($value);
                break;
            case 'float':
                return floatval($value);
                break;
            case 'string':
                return $value;
                break;
            default:
                return $value;
                break;
        }
    }
}<commit_msg>Optimize code styleing<commit_after><?php

namespace App\Traits;

use App\Preference;

trait Preferenceable
{
    public function preferences()
    {
        return $this->morphMany('App\Preference', 'preferenceable');
    }

    public function pref($key, $value = null, $type = 'string')
    {
        if (isset($value)) {
            $this->preferences()->updateOrCreate(['key' => $key], ['value' => $this->cast($value, $type),
                                                                   'type' => $type]);
            return $value;
        }
        $default = Preference::getDefault($this, $key);
        return($pref = $this->preferences()->forKey($key)->first()) ? $pref->value() : $default->value();
    }

    private function cast($value, $type)
    {
        switch ($type) {
            case 'bool':
                return boolval($value);
            break;
            case 'int':
                return intval($value);
            break;
            case 'float':
                return floatval($value);
            break;
            case 'string':
                return $value;
            break;
            default:
                return $value;
            break;
        }
    }
}
{'fraction_non_alphanumeric': 0.14795918367346939, 'fraction_numerical': 0.0, 'mean_word_length': 1.5301075268817204, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3282840', 'n_tokens_mistral': 633, 'n_tokens_neox': 619, 'n_words': 136}