Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix json encode null #120

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

datlechin
Copy link
Contributor

@datlechin datlechin commented Jul 6, 2024

Fix json encode null in php8.3

Fixes #0000

Changes proposed in this pull request:

Reviewers should focus on:

Screenshot

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tests are green (run composer test).

Required changes:

Copy link
Member

@DavideIadeluca DavideIadeluca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with this, but I think it would make sense to simplify the surrounding logic a little while already at it:

public function handle(SettingsRepositoryInterface $settings, Dispatcher $dispatcher)
{
    $autoAssignGroups = $settings->get('fof-gamification.autoAssignedGroups');
    
    // If the setting is missing or empty, or if the subject user is an admin, we can skip this job
    if (empty($autoAssignGroups) || $this->user->isAdmin()) {
        return;
    }

    $entries = json_decode($autoAssignGroups, true);
..
}

Copy link
Member

@DavideIadeluca DavideIadeluca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @datlechin!

@luceos
Copy link
Contributor

luceos commented Jul 24, 2024

@DavideIadeluca if you want to do an optimization, although just a slight one, stop early instead of accessing the settings repository first (which you then don't need for an admin):

        if ($this->user->isAdmin()) return;

        return json_decode(
                $settings->get('fof-gamification.autoAssignGroups', '[]'),
                true
        );

@DavideIadeluca
Copy link
Member

@DavideIadeluca if you want to do an optimization, although just a slight one, stop early instead of accessing the settings repository first (which you then don't need for an admin):

        if ($this->user->isAdmin()) return;

        return json_decode(
                $settings->get('fof-gamification.autoAssignGroups', '[]'),
                true
        );

Yeah right, makes sense. @datlechin Can you please use the suggestion of @luceos instead? 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants