<commit_before><?php

// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

declare(strict_types=1);

namespace App\Libraries;

use App\Jobs\Notifications;
use App\Models\BeatmapDiscussion;
use App\Models\User;

abstract class BeatmapsetDiscussionPostHandlesProblem
{
    protected int $priorOpenProblemCount = 0;
    protected ?BeatmapDiscussion $problemDiscussion = null;
    protected User $user;

    protected function handleProblemDiscussion()
    {
        if ($this->problemDiscussion === null) {
            return;
        }

        $beatmapset = $this->problemDiscussion->beatmapset;

        if ($this->shouldDisqualifyOrResetNominations()) {
            return $beatmapset->disqualifyOrResetNominations($this->user, $this->problemDiscussion);
        }

        if ($beatmapset->isQualified() && $this->priorOpenProblemCount === 0 && !$this->problemDiscussion->resolved) {
            (new Notifications\BeatmapsetDiscussionQualifiedProblem(
                $this->problemDiscussion->startingPost,
                $this->user
            ))->dispatch();
        }
    }

    protected function shouldDisqualifyOrResetNominations(): bool
    {
        // disqualify or reset nominations requires a new discussion.
        if ($this->problemDiscussion->wasRecentlyCreated || !$this->problemDiscussion->exists) {
            $beatmapset = $this->problemDiscussion->beatmapset;
            if ($beatmapset->isQualified()) {
                if (priv_check_user($this->user, 'BeatmapsetDisqualify', $beatmapset)->can()) {
                    return true;
                }
            }

            if ($beatmapset->isPending()) {
                if ($beatmapset->hasNominations() && priv_check_user($this->user, 'BeatmapsetResetNominations', $beatmapset)->can()) {
                    return true;
                }
            }
        }

        return false;
    }
}<commit_msg>no need to fall through; that part was removed earlier<commit_after><?php

// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

declare(strict_types=1);

namespace App\Libraries;

use App\Jobs\Notifications;
use App\Models\BeatmapDiscussion;
use App\Models\User;

abstract class BeatmapsetDiscussionPostHandlesProblem
{
    protected int $priorOpenProblemCount = 0;
    protected ?BeatmapDiscussion $problemDiscussion = null;
    protected User $user;

    protected function handleProblemDiscussion()
    {
        if ($this->problemDiscussion === null) {
            return;
        }

        $beatmapset = $this->problemDiscussion->beatmapset;

        if ($this->shouldDisqualifyOrResetNominations()) {
            return $beatmapset->disqualifyOrResetNominations($this->user, $this->problemDiscussion);
        }

        if ($beatmapset->isQualified() && $this->priorOpenProblemCount === 0 && !$this->problemDiscussion->resolved) {
            (new Notifications\BeatmapsetDiscussionQualifiedProblem(
                $this->problemDiscussion->startingPost,
                $this->user
            ))->dispatch();
        }
    }

    protected function shouldDisqualifyOrResetNominations(): bool
    {
        // disqualify or reset nominations requires a new discussion.
        if ($this->problemDiscussion->wasRecentlyCreated || !$this->problemDiscussion->exists) {
            $beatmapset = $this->problemDiscussion->beatmapset;
            if ($beatmapset->isQualified()) {
                return priv_check_user($this->user, 'BeatmapsetDisqualify', $beatmapset)->can();
            } elseif ($beatmapset->isPending()) {
                return $beatmapset->hasNominations()
                    && priv_check_user($this->user, 'BeatmapsetResetNominations', $beatmapset)->can();
            }
        }

        return false;
    }
}
{'fraction_non_alphanumeric': 0.11466733870967742, 'fraction_numerical': 0.0025201612903225806, 'mean_word_length': 2.671600370027752, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 63, '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': '5559931', 'n_tokens_mistral': 1150, 'n_tokens_neox': 1041, 'n_words': 227}