Question about ServerRequestInterface vs RequestInterface

Our setup:

The relevant part of index file:

// Build DI Container instance
$container = (new ContainerFactory())->createInstance();

// Create the nyholm server request creator.
$nyholmFactory = $container->get(Psr17Factory::class);
$decoratedRequestFactory = new DecoratedServerRequestFactory($nyholmFactory);

$creator = new ServerRequestCreator(
    $nyholmFactory, $nyholmFactory, $nyholmFactory, $nyholmFactory
);

// Create the request.
$request = $creator->fromGlobals();

// Set container to create App with on AppFactory
$app = $container->get(App::class);

// Add Routing Middleware
$app->addRoutingMiddleware();

// Run App & Emit Response
$response = $app->handle($request);
$responseEmitter = new ResponseEmitter();
$responseEmitter->emit($response);

And in our Controllers we have been doing this (maybe leftover from before nyholm):

use Psr\Http\Message\RequestInterface as Request;

and on the methods:

/**
     * @param \Psr\Http\Message\RequestInterface $request
     * @param \Psr\Http\Message\ResponseInterface $response
     * @param array $args
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function complete(Request $request, Response $response, $args): Response {

Everything runs and works fine like this - and has been fine since we switched to Nyholm (I believe we had our own RequestHandler in between before Nyholm)

PHPStan complains about this setup when we have to use RouteContext

$routeParser = RouteContext::fromRequest($request)->getRouteParser();

Parameter #1 $serverRequest of static method Slim\Routing\RouteContext::fromRequest() expects Psr\Http\Message\ServerRequestInterface, Psr\Http\Message\RequestInterface given.

What is the correct way here?

I see that:

interface ServerRequestInterface extends RequestInterface \Psr\Http\Message\ServerRequestInterface

As a test I changed all references for Psr\Http\Message\RequestInterface to Psr\Http\Message\ServerRequestInterface in the controller that used RouteContext and it seems to be functioning fine still.

I would guess this line might cause the issue. Have you tried to replace it with the ServerRequestInterface?

use Psr\Http\Message\ServerRequestInterface as Request;

Yes I did try replacing it and it seems to work just fine - which makes sense given that it extends RequestInterface.

I just wanted to make sure I wasn’t going to be changing it to that and then go against some PSR way of doing.