sonata-project / SonataBlockBundle

Symfony SonataBlockBundle
https://docs.sonata-project.org/projects/SonataBlockBundle
MIT License
413 stars 141 forks source link

Increase PHPStan and Psalm #1052

Closed jordisala1991 closed 2 years ago

jordisala1991 commented 2 years ago

Subject

I am targeting this branch, because applying this to 5.x is easier due to deprecated code removed.

jordisala1991 commented 2 years ago

There are a lot of deprecated code on 4.x that makes difficult to increase psalm there, wdyt on doing it directly for 5.x?

jordisala1991 commented 2 years ago

Not sure how to deal with:

ERROR: DocblockTypeContradiction - src/Block/BlockLoaderChain.php:52:13 - Docblock-defined type array<string, mixed> for $configuration is always array (see https://psalm.dev/155)
        if (!\is_string($configuration) && !\is_array($configuration)) {

ERROR: DocblockTypeContradiction - src/Block/BlockLoaderChain.php:71:13 - Docblock-defined type array<string, mixed> for $configuration is always array (see https://psalm.dev/155)
        if (!\is_string($configuration) && !\is_array($configuration)) {

ERROR: RedundantConditionGivenDocblockType - src/Block/BlockServiceManager.php:89:17 - Docblock-defined type Sonata\BlockBundle\Block\Service\BlockServiceInterface for $service is always object (see https://psalm.dev/156)
                \is_object($service) ? \get_class($service) : \gettype($service)

ERROR: DocblockTypeContradiction - src/Block/BlockServiceManager.php:89:63 - Docblock-defined type Sonata\BlockBundle\Block\Service\BlockServiceInterface for $service is always object (see https://psalm.dev/155)
                \is_object($service) ? \get_class($service) : \gettype($service)

ERROR: DocblockTypeContradiction - src/Block/Loader/ServiceLoader.php:47:13 - Docblock-defined type array<string, mixed> for $configuration is always array (see https://psalm.dev/155)
        if (!\is_string($configuration) && !\is_array($configuration)) {

ERROR: DocblockTypeContradiction - src/Block/Loader/ServiceLoader.php:81:13 - Docblock-defined type array<string, mixed> for $configuration is always array (see https://psalm.dev/155)
        if (!\is_string($configuration) && !\is_array($configuration)) {

Psalm is right, PHPDOC says we pass array or string and we are checking for it because its only phpdoc , no real typing. For PHPStan we enable the "Do not trust phpdoc" flag, but what should we do for Psalm?

VincentLanglet commented 2 years ago

https://github.com/sonata-project/SonataDoctrineORMAdminBundle/blob/4.x/psalm.xml#L15-L19

?

dmaicher commented 2 years ago

Can you wait for my merge and NEXT_MAJOR cleanup? There might be more stuff to fix :see_no_evil:

jordisala1991 commented 2 years ago

Can you wait for my merge and NEXT_MAJOR cleanup? There might be more stuff to fix 🙈

Ofc I can wait, anyway think of it as an improvement to catch errors made during deprecation PRs, so getting an error on a cleanup PR might save time of bug fixing later

dmaicher commented 2 years ago

Everything is merged now. Can you rebase?