<commit_before><?php
namespace KDuma\Eloquent;

use Illuminate\Support\Str;


/**
 * Class Slugabble
 * @package KDuma\Eloquent
 */
trait Slugabble {


    /**
     * @return mixed
     */
    protected function getSluggableString(){
        if(method_exists($this, 'SluggableString'))
            return $this->SluggableString();
        return $this->title;
    }


    /**
     * @param $title
     * @param int $duplicates_count
     * @return string
     */
    protected static function makeSlug($title, $duplicates_count = 0)
    {
        $duplicates_count = (int) $duplicates_count;

        $slug = $title = Str::slug($title);

        if($slug == $this->slug)
            return $slug;

        if ($duplicates_count > 0) {
            $slug = $slug.'-'.$duplicates_count;
            $rowCount = \DB::table($this->getTable())->where('slug', $slug)->count();
            if ($rowCount > 0) {
                return static::makeSlug($title, ++$duplicates_count);
            } else {
                return $slug;
            }
        } else {
            $rowCount = \DB::table($this->getTable())->where('slug', $title)->count();
            if ($rowCount > 0) {
                return static::makeSlug($title, ++$duplicates_count);
            } else {
                return $title;
            }
        }
    }

    /**
     * Generates slug
     */
    public function newSlug(){<commit_msg>Make function non-static<commit_after><?php
namespace KDuma\Eloquent;

use Illuminate\Support\Str;


/**
 * Class Slugabble
 * @package KDuma\Eloquent
 */
trait Slugabble {


    /**
     * @return mixed
     */
    protected function getSluggableString(){
        if(method_exists($this, 'SluggableString'))
            return $this->SluggableString();
        return $this->title;
    }


    /**
     * @param $title
     * @param int $duplicates_count
     * @return string
     */
    protected function makeSlug($title, $duplicates_count = 0)
    {
        $duplicates_count = (int) $duplicates_count;

        $slug = $title = Str::slug($title);

        if($slug == $this->slug)
            return $slug;

        if ($duplicates_count > 0) {
            $slug = $slug.'-'.$duplicates_count;
            $rowCount = \DB::table($this->getTable())->where('slug', $slug)->count();
            if ($rowCount > 0) {
                return $this->makeSlug($title, ++$duplicates_count);
            } else {
                return $slug;
            }
        } else {
            $rowCount = \DB::table($this->getTable())->where('slug', $title)->count();
            if ($rowCount > 0) {
                return $this->makeSlug($title, ++$duplicates_count);
            } else {
                return $title;
            }
        }
    }

    /**
     * Generates slug
     */
    public function newSlug(){
{'fraction_non_alphanumeric': 0.15223562810503904, 'fraction_numerical': 0.0028388928317956, 'mean_word_length': 1.8218218218218218, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '3544749', 'n_tokens_mistral': 886, 'n_tokens_neox': 877, 'n_words': 160}