<commit_before><?php

namespace MyBB\Core\Database\Repositories\Eloquent;

use Illuminate\Support\Collection;
use MyBB\Core\Database\Models\ProfileField;
use MyBB\Core\Database\Models\ProfileFieldGroup;
use MyBB\Core\Database\Models\User;
use MyBB\Core\Database\Models\UserProfileField;
use MyBB\Core\Database\Repositories\UserProfileFieldRepositoryInterface;

class UserProfileFieldRepository implements UserProfileFieldRepositoryInterface
{
    /**
     * @var UserProfileField
     */
    protected $userProfileField;

    /**
     * @param UserProfileField $userProfileField
     */
    public function __construct(UserProfileField $userProfileField)
    {
        $this->userProfileField = $userProfileField;
    }

    /**
     * @param User $user
     * @param ProfileField $profileField
     * @param string $value
     *
     * @return UserProfileField
     */
    public function create(User $user, ProfileField $profileField, $value)
    {
        return $this->userProfileField->create([
            'user_id' => $user->getId(),
            'profile_field_id' => $profileField->id,
            'value' => $value
        ]);
    }

    /**
     * @param int $id
     *
     * @return UserProfileField
     */
    public function find($id)
    {
        return $this->userProfileField->find($id);
    }

    /**
     * @param User $user
     * @param ProfileField $profileField
     *
     * @return UserProfileField
     */
    public function findForProfileField(User $user, ProfileField $profileField)
    {
        return $this->userProfileField->where('user_id', $user->getId())
            ->where('profile_field_id', $profileField->id)
            ->get()
            ->first();
    }

    /**
     * @param User $user
     * @param ProfileField $profileField
     * @param string $value
     *
     * @return UserProfileField
     */
    public function updateOrCreate(User $user, ProfileField $profileField, $value)
    {
        $userProfileField = $this->findForProfileField($user, $profileField);

        if ($userProfileField) {
            $userProfileField->setValue($value);
            $userProfileField->save();
            return $userProfileField;
        }

        return $this->create($user, $profileField, $value);
    }

    /**
     * @param User $user
     *
     * @return Collection
     */
    public function findForUser(User $user)
    {
        return $this->userProfileField->where('user_id', $user->getId())->get();
    }

    /**
     * @param User $user
     * @param ProfileFieldGroup $group
     *
     * @return Collection
     */
    public function findForProfileFieldGroup(User $user, ProfileFieldGroup $group)
    {
        $userFields = $this->userProfileField->where('user_id', $user->getId())
            ->whereHas('getProfileField', function ($q) use ($group) {
                $q->where('profile_field_group_id', $group->id);
            })
            ->get();

        return $userFields;
    }

    /**
     * @param User $user
     * @param ProfileField $profileField
     *
     * @return bool
     */
    public function hasForProfileField(User $user, ProfileField $profileField)
    {
        return $this->userProfileField->where('user_id', $user->getId())
            ->where('profile_field_id', $profileField->id)
            ->count() > 0;
    }
}
<commit_msg>Add missing Query\Builder type hint<commit_after><?php

namespace MyBB\Core\Database\Repositories\Eloquent;

use Illuminate\Database\Query\Builder;
use Illuminate\Support\Collection;
use MyBB\Core\Database\Models\ProfileField;
use MyBB\Core\Database\Models\ProfileFieldGroup;
use MyBB\Core\Database\Models\User;
use MyBB\Core\Database\Models\UserProfileField;
use MyBB\Core\Database\Repositories\UserProfileFieldRepositoryInterface;

class UserProfileFieldRepository implements UserProfileFieldRepositoryInterface
{
    /**
     * @var UserProfileField
     */
    protected $userProfileField;

    /**
     * @param UserProfileField $userProfileField
     */
    public function __construct(UserProfileField $userProfileField)
    {
        $this->userProfileField = $userProfileField;
    }

    /**
     * @param User $user
     * @param ProfileField $profileField
     * @param string $value
     *
     * @return UserProfileField
     */
    public function create(User $user, ProfileField $profileField, $value)
    {
        return $this->userProfileField->create([
            'user_id' => $user->getId(),
            'profile_field_id' => $profileField->id,
            'value' => $value
        ]);
    }

    /**
     * @param int $id
     *
     * @return UserProfileField
     */
    public function find($id)
    {
        return $this->userProfileField->find($id);
    }

    /**
     * @param User $user
     * @param ProfileField $profileField
     *
     * @return UserProfileField
     */
    public function findForProfileField(User $user, ProfileField $profileField)
    {
        return $this->userProfileField->where('user_id', $user->getId())
            ->where('profile_field_id', $profileField->id)
            ->get()
            ->first();
    }

    /**
     * @param User $user
     * @param ProfileField $profileField
     * @param string $value
     *
     * @return UserProfileField
     */
    public function updateOrCreate(User $user, ProfileField $profileField, $value)
    {
        $userProfileField = $this->findForProfileField($user, $profileField);

        if ($userProfileField) {
            $userProfileField->setValue($value);
            $userProfileField->save();
            return $userProfileField;
        }

        return $this->create($user, $profileField, $value);
    }

    /**
     * @param User $user
     *
     * @return Collection
     */
    public function findForUser(User $user)
    {
        return $this->userProfileField->where('user_id', $user->getId())->get();
    }

    /**
     * @param User $user
     * @param ProfileFieldGroup $group
     *
     * @return Collection
     */
    public function findForProfileFieldGroup(User $user, ProfileFieldGroup $group)
    {
        $userFields = $this->userProfileField->where('user_id', $user->getId())
            ->whereHas('getProfileField', function (Builder $q) use ($group) {
                $q->where('profile_field_group_id', $group->id);
            })
            ->get();

        return $userFields;
    }

    /**
     * @param User $user
     * @param ProfileField $profileField
     *
     * @return bool
     */
    public function hasForProfileField(User $user, ProfileField $profileField)
    {
        return $this->userProfileField->where('user_id', $user->getId())
            ->where('profile_field_id', $profileField->id)
            ->count() > 0;
    }
}

{'fraction_non_alphanumeric': 0.12995692856081983, 'fraction_numerical': 0.0002970444081390168, 'mean_word_length': 2.449795081967213, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 81, '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': '5325212', 'n_tokens_mistral': 1927, 'n_tokens_neox': 1920, 'n_words': 367}