phpstan-typo3 icon indicating copy to clipboard operation
phpstan-typo3 copied to clipboard

Possible improvement of the default requestGetAttributeMapping for "site"

Open ervaude opened this issue 2 years ago • 3 comments

Hi, I just noticed, that $request->getAttribute('site') is by default configured to return a Site object. The attribute could, however, also hold an instance of NullSite, so I reconfigured the requestGetAttributeMapping for site in our projects to the SiteInterface.

parameters:
    typo3:
        requestGetAttributeMapping:
            site: TYPO3\CMS\Core\Site\Entity\SiteInterface

Maybe you want to adjust the default configuration? Note, that this would likely lead to some new error reports for people, so if you don't want to do it, just close this issue :)

Thanks for this great package, we use it a lot.

Cheers

ervaude avatar Feb 13 '23 11:02 ervaude

You're right. I'm a bit scared to change it as we then have again a change that required a large set of code to be "guarded" in many projects. It would be pretty cool to be able to limit this to phpstan setups that your running with a high level but not for setups with low levels. I've created an issue in PHPStan to ask about such a "level based config file load support". https://github.com/phpstan/phpstan/issues/8887

sascha-egerer avatar Feb 13 '23 15:02 sascha-egerer

The attribute could, however, also hold an instance of NullSite, so I reconfigured the requestGetAttributeMapping for site in our projects to the SiteInterface.

That's technically right but it shows how bad this new kind of API actually is. What I usually want from the site, is the router. And that's only accessible through the implementation, not the interface. Even worse: Router needs a Site as constructor argument, not a SiteInterface. So, where do you reliably get a Site from? Not just during runtime, but also during static code analysis?

I think the core needs to streamline things and this issue is just a symptom of a pain that isn't caused by phpstan.

Another example is the routing attribute. Early in the middleware stack it holds an instance of SiteRouteResult, later in the stack it's overridden with an instance of PageArguments. Just horrible. And this is not a rant. I just saw this issue and was working on the aspects, another (still new enough) api which is annoying. ^^

alexanderschnitzler avatar Jun 14 '23 18:06 alexanderschnitzler

@sascha-egerer I would not change it now. Only with a new release. Everyone can configure it nonetheless.

sabbelasichon avatar Feb 21 '24 11:02 sabbelasichon