<commit_before><?php

namespace MadWeb\Seoable\Traits;

use MadWeb\Seoable\Protocols\Meta;

/**
 * This trait is for usage in models.
 */
trait SeoableTrait
{
    /**
     * Has one polymorphic relation to seo storage table.
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function seoData()
    {
        $class_name = get_class($this);

        $SeoDataQuery = $this->hasOne(config('seoable.model'), 'seoable_id')->where('seoable_type', $class_name);

        if (! $SeoDataQuery->exists()) {
            $SeoData = $SeoDataQuery->make(['meta' => [], 'open_graph' => [], 'twitter' => []]);
            $SeoData->seoable_type = $class_name;
            $SeoData->save();
        }

        return $SeoDataQuery;
    }

    /**
     * Get seo data from the table.
     *
     * @return mixed
     */
    public function getSeoData()
    {
        return $this->seoData->getSeoData();
    }

    protected function seo()
    {
        return new Meta($this);
    }
}
<commit_msg>Fixed seo data creation for non existing model<commit_after><?php

namespace MadWeb\Seoable\Traits;

use MadWeb\Seoable\Protocols\Meta;

/**
 * This trait is for usage in models.
 */
trait SeoableTrait
{
    /**
     * Has one polymorphic relation to seo storage table.
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function seoData()
    {
        $class_name = get_class($this);

        $SeoDataQuery = $this->hasOne(config('seoable.model'), 'seoable_id')->where('seoable_type', $class_name);

        if (! $SeoDataQuery->exists() and $this->exists) {
            $SeoData = $SeoDataQuery->make(['meta' => [], 'open_graph' => [], 'twitter' => []]);
            $SeoData->seoable_type = $class_name;
            $SeoData->save();
        }

        return $SeoDataQuery;
    }

    /**
     * Get seo data from the table.
     *
     * @return mixed
     */
    public function getSeoData()
    {
        return $this->seoData->getSeoData();
    }

    protected function seo()
    {
        return new Meta($this);
    }
}

{'fraction_non_alphanumeric': 0.14901772879731673, 'fraction_numerical': 0.0, 'mean_word_length': 2.2985781990521326, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 26, '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': '213576', 'n_tokens_mistral': 703, 'n_tokens_neox': 692, 'n_words': 135}