PHP Psalm warning for RouteServiceProvider configureRateLimiting method

When running psalm in a Laravel project, I get the following error by default:

PossiblyNullArgument - app/Providers/RouteServiceProvider.php:45:46 - 
Argument 1 of Illuminate\Cache\RateLimiting\Limit::by cannot be null, 
possibly null value provided

This is the default implementation for configureRateLimiting in the RouteServiceProvider class in Laravel:

protected function configureRateLimiting()
{
    RateLimiter::for('api', function (Request $request) {
        return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
    });
}

I change it to the following to get psalm to pass (I’ve added named parameters and the static keyword before the callback function):

protected function configureRateLimiting()
{
    RateLimiter::for(name: 'api', callback: static function (Request $request) {
        $limitIdentifier = $request->user()?->id ?: $request->ip();
        if (!is_null($limitIdentifier)) {
            return Limit::perMinute(maxAttempts: 60)->by(key: $limitIdentifier);
        }
    });
}

Website under construction

I’ve always believed that people should own and control their own place on the web. That is, if they want to.

I have actively kept a personal website for myself for about 10 years now.

Gosh… 10 years…

In that time I have moved between about 5 different domain names, different focus topics, and different reasoning behind why I want to publish online.

I have finally settled now on this domain that you are now on – davidpeach.me.

I’m also in the process of recovering my old posts that have been thrown by the wayside as I have dicked about changing domain names etc over the years.

A mixture of Twitter archives, manual database backups I have kept, and some new sources I will be incorporating, mean I am finally going to settle down in this place online I am now calling home.

I am also re-implementing aspects of the Indieweb movement for content ownership and communicating that to other websites.

I owe a big thank you to Chris Aldrich too. As it was his website I came across that inspired me to bring my website back to what I have always wanted it to be. Hopefully, thanks to the indieweb helper plugins I have installed, Chris may just get notified on his website and post a reply back — from his website over to mine using the webmention protocol.