<commit_before><?php

namespace TypiCMS\Modules\Tags\Repositories;

use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use stdClass;
use TypiCMS\Modules\Core\Repositories\EloquentRepository;
use TypiCMS\Modules\Tags\Models\Tag;

class EloquentTag extends EloquentRepository
{
    protected $repositoryId = 'tags';

    protected $model = Tag::class;

    /**
     * Get paginated models.
     *
     * @param int   $page  Number of models per page
     * @param int   $limit Results per page
     * @param bool  $all   get published models or all
     * @param array $with  Eager load related models
     *
     * @return stdClass Object with $items && $totalItems for pagination
     */
    public function byPage($page = 1, $limit = 10, array $with = [], $all = false)
    {
        $result = new stdClass();
        $result->page = $page;
        $result->limit = $limit;
        $result->totalItems = 0;
        $result->items = [];

        $model = $this->createModel();

        $query = $model->select(
            'id',
            'tag',
            'slug',
            DB::raw(
                '(SELECT COUNT(*) FROM `'.
                DB::getTablePrefix().
                'taggables` WHERE `tag_id` = `'.
                DB::getTablePrefix().
                "tags`.`id`) AS 'uses'"
            )
        )
        ->order();

        $models = $query->skip($limit * ($page - 1))
                        ->take($limit)
                        ->get();

        // Put items and totalItems in stdClass
        $result->totalItems = $model->count();
        $result->items = $models->all();

        return $result;
    }

    /**
     * Get all tags with uses count.
     *
     * @return Collection
     */
    public function allWithUses()
    {
        $query = $this->createModel()->select(
            'id',
            'tag',
            'slug',
            DB::raw(
                '(SELECT COUNT(*) FROM `'.
                DB::getTablePrefix().
                'taggables` WHERE `tag_id` = `'.
                DB::getTablePrefix().
                "tags`.`id`) AS 'uses'"
            )
        )
        ->orderBy('uses', 'desc');

        return $query->get();
    }

    /**
     * Get all models.
     *
     * @param bool  $all  Show published or all
     * @param array $with Eager load related models
     *
     * @return Collection
     */
    public function all(array $with = [], $all = false)
    {
        return $this->model->select('id', 'tag', 'slug')->order()->get();
    }

    /**
     * Find existing tags or create if they don't exist.
     *
     * @param array $tags Array of strings, each representing a tag
     *
     * @return array Array or Arrayable collection of Tag objects
     */
    public function findOrCreate(array $tags)
    {
        $foundTags = $this->findWhereIn(['tag', $tags]);
<commit_msg>unused methods<commit_after><?php

namespace TypiCMS\Modules\Tags\Repositories;

use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use stdClass;
use TypiCMS\Modules\Core\Repositories\EloquentRepository;
use TypiCMS\Modules\Tags\Models\Tag;

class EloquentTag extends EloquentRepository
{
    protected $repositoryId = 'tags';

    protected $model = Tag::class;

    /**
     * Get all tags with uses count.
     *
     * @return Collection
     */
    public function allWithUses()
    {
        $query = $this->createModel()->select(
            'id',
            'tag',
            'slug',
            DB::raw(
                '(SELECT COUNT(*) FROM `'.
                DB::getTablePrefix().
                'taggables` WHERE `tag_id` = `'.
                DB::getTablePrefix().
                "tags`.`id`) AS 'uses'"
            )
        )
        ->orderBy('uses', 'desc');

        return $query->get();
    }

    /**
     * Find existing tags or create if they don't exist.
     *
     * @param array $tags Array of strings, each representing a tag
     *
     * @return array Array or Arrayable collection of Tag objects
     */
    public function findOrCreate(array $tags)
    {
        $foundTags = $this->findWhereIn(['tag', $tags]);

{'fraction_non_alphanumeric': 0.1351031050011851, 'fraction_numerical': 0.0011851149561507466, 'mean_word_length': 1.8152101400933955, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, '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': '1763203', 'n_tokens_mistral': 1250, 'n_tokens_neox': 1216, 'n_words': 312}