<commit_before><?php namespace TeamTeaTime\Counter;

use TeamTeaTime\Counter\Count;

trait HasCounters
{

    public function counts()
    {
        return $this->morphMany('TeamTeaTime\Counter\Count', 'model');
    }

    /**
     * Increment a counter
     *
     * @param   $key            Key of the counter to increment.
     *          string
     *
     * @param   $options        Array of optional settings.
     *
     * @return  TeamTeaTime\Counter\Count
     */
    public function incrementCount($key, $options = array())
    {
        // Merge in default options
        $options += [
            'amount'    => 1,
            'user_id'   => 'callback'
        ];

        if ($options['user_id'] == 'callback') {
            $userIDCallback = config('filer.user.id');
            $userID = $userIDCallback();
        } else {
            $userID = $options['user_id'];
        }

        // Create/update and save the count
        $count = Count::firstOrNew([
            'user_id'   => $userID,
            'model_id'  => $this->id,
            'key'       => $options['key']
        ]);
        $count->count = $count->count + $options['amount'];
        $count->save();

        // Save the current model to the attachment
        $this->counts()->save($count);

        return $count;
    }

}<commit_msg>Update HasCounters.php<commit_after><?php namespace TeamTeaTime\Counter;

use TeamTeaTime\Counter\Count;

trait HasCounters
{

    public function counts()
    {
        return $this->morphMany('TeamTeaTime\Counter\Count', 'model');
    }

    /**
     * Increment a counter
     *
     * @param   $key            Key of the counter to increment.
     *          string
     *
     * @param   $options        Array of optional settings.
     *
     * @return  TeamTeaTime\Counter\Count
     */
    public function incrementCount($key, $options = array())
    {
        // Merge in default options
        $options += [
            'amount'    => 1,
            'user_id'   => 'callback'
        ];

        if ($options['user_id'] == 'callback') {
            $userIDCallback = config('counter.user.id');
            $userID = $userIDCallback();
        } else {
            $userID = $options['user_id'];
        }

        // Create/update and save the count
        $count = Count::firstOrNew([
            'user_id'   => $userID,
            'model_id'  => $this->id,
            'key'       => $key
        ]);
        $count->count = $count->count + $options['amount'];
        $count->save();

        // Save the current model to the attachment
        $this->counts()->save($count);

        return $count;
    }

}
{'fraction_non_alphanumeric': 0.14086102719033233, 'fraction_numerical': 0.0007552870090634441, 'mean_word_length': 1.6730575176589304, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3419140', 'n_tokens_mistral': 777, 'n_tokens_neox': 766, 'n_words': 169}