<commit_before><?php declare(strict_types=1);

namespace PAF\Modules\CommonModule\Repository;

use Nette\InvalidStateException;
use Nette\Utils\Strings;
use PAF\Common\Lean\BaseRepository;
use PAF\Modules\CommonModule\Model\Slug;

/**
 * Universally unique slug repository
 */
class SlugRepository extends BaseRepository
{

    public function slugExists(string $slug): bool
    {
        $result = $this->select()->where([
            'id' => $slug,
        ])->fetch();

        return !!$result;
    }

    public function createSlug(string $string, bool $numberSuffixIfExists = false): Slug
    {
        $slugId = Strings::trim(Strings::webalize($string), '-');

        if ($this->slugExists($slugId)) {
            if (!$numberSuffixIfExists) {
                throw new InvalidStateException('paf.case.already-exists');
            }
            $sequence = $this->getMaxSlugSuffix($slugId) + 1;
            $slugId = "$slugId-$sequence";
        }
        $slug = new Slug();
        $slug->id = $slugId;

        $this->persist($slug);

        return $slug;
    }

    protected function getMaxSlugSuffix(string $slug): int
    {
        $maxSlug = $this->select('id')
            ->where('id LIKE %s', $slug . '%')
            ->orderBy('id DESC')
            ->limit(1)
            ->fetchSingle();

        $parts = explode('-', $maxSlug);
        $suffix = end($parts);
        if (!is_numeric($suffix)) {
            return 1;
        }


        return (int)$suffix;
    }
}<commit_msg>Code style fix<commit_after><?php declare(strict_types=1);

namespace PAF\Modules\CommonModule\Repository;

use Nette\InvalidStateException;
use Nette\Utils\Strings;
use PAF\Common\Lean\BaseRepository;
use PAF\Modules\CommonModule\Model\Slug;

/**
 * Universally unique slug repository
 */
class SlugRepository extends BaseRepository
{

    public function slugExists(string $slug): bool
    {
        $result = $this->select()->where([
            'id' => $slug,
        ])->fetch();

        return !!$result;
    }

    public function createSlug(string $string, bool $numberSuffixIfExists = false): Slug
    {
        $slugId = Strings::trim(Strings::webalize($string), '-');

        if ($this->slugExists($slugId)) {
            if (!$numberSuffixIfExists) {
                throw new InvalidStateException('paf.case.already-exists');
            }
            $sequence = $this->getMaxSlugSuffix($slugId) + 1;
            $slugId = "$slugId-$sequence";
        }
        $slug = new Slug();
        $slug->id = $slugId;

        $this->persist($slug);

        return $slug;
    }

    protected function getMaxSlugSuffix(string $slug): int
    {
        $maxSlug = $this->select('id')
            ->where('id LIKE %s', $slug . '%')
            ->orderBy('id DESC')
            ->limit(1)
            ->fetchSingle();

        $parts = explode('-', $maxSlug);
        $suffix = end($parts);
        if (!is_numeric($suffix)) {
            return 1;
        }

        return (int)$suffix;
    }
}
{'fraction_non_alphanumeric': 0.15169660678642716, 'fraction_numerical': 0.0026613439787092482, 'mean_word_length': 2.2057569296375266, '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': '4888161', 'n_tokens_mistral': 928, 'n_tokens_neox': 925, 'n_words': 178}