<commit_before><?php

namespace TypiCMS\Modules\Tags\Observers;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Request;
use Tags;

class TagObserver
{
    /**
     * On save, process tags.
     *
     * @param Model $model eloquent
     *
     * @return mixed false or void
     */
    public function saved(Model $model)
    {
        $tags = $this->processTags(Request::input('tags'));
        $this->syncTags($model, $tags);
    }

    /**
     * Convert string of tags to array.
     *
     * @param  string
     *
     * @return array
     */
    protected function processTags($tags)
    {
        if (!$tags) {
            return [];
        }

        $tags = explode(',', $tags);

        foreach ($tags as $key => $tag) {
            $tags[$key] = trim($tag);
        }

        return $tags;
    }

    /**<commit_msg>don't process tags when input is null<commit_after><?php

namespace TypiCMS\Modules\Tags\Observers;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Request;
use Tags;

class TagObserver
{
    /**
     * On save, process tags.
     *
     * @param Model $model eloquent
     *
     * @return mixed false or void
     */
    public function saved(Model $model)
    {
        if (is_null(Request::input('tags'))) {
            return;
        }
        $tags = $this->processTags(Request::input('tags'));
        $this->syncTags($model, $tags);
    }

    /**
     * Convert string of tags to array.
     *
     * @param  string
     *
     * @return array
     */
    protected function processTags($tags)
    {
        if (!$tags) {
            return [];
        }

        $tags = explode(',', $tags);

        foreach ($tags as $key => $tag) {
            $tags[$key] = trim($tag);
        }

        return $tags;
    }

    /**
{'fraction_non_alphanumeric': 0.1414141414141414, 'fraction_numerical': 0.0, 'mean_word_length': 1.904320987654321, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '791444', 'n_tokens_mistral': 588, 'n_tokens_neox': 590, 'n_words': 133}