8000 [PropertyInfo] PhpStanTypeHelper doesn't support ConstTypeNode · Issue #44491 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[PropertyInfo] PhpStanTypeHelper doesn't support ConstTypeNode #44491

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

Closed
ostrolucky opened this issue Dec 7, 2021 · 2 comments
Closed

[PropertyInfo] PhpStanTypeHelper doesn't support ConstTypeNode #44491

ostrolucky opened this issue Dec 7, 2021 · 2 comments

Comments

@ostrolucky
Copy link
Contributor
ostrolucky commented Dec 7, 2021

Description

After updating from Symfony 5.3 to Symfony 5.4, our code started to crash. This is because new PhpStanExtractor was introduced that was prioritized above older extractors. This extractor started to return null type and hence serializer failed to denormalize our objects.

It returns null, because this is a UnionTypeNode containing ConstTypeNode and IdentifierTypeNode (null). However PhpStanTypeHelper doesn't handle ConstTypeNode and hence symfony/property-info will return null only.

Example

class Foo
{
   /**
     * @return PageType::*|null
     */
    public function getDynamicPageType(): ?string
    {
        return rand(0, 1) ? PageType::FOO : null;
    }
}

class PageType {
    const FOO = 'foo';
}

On Symfony 5.3, this returns string|null. On Symfony 5.4, because PhpStanExtractor was added which doesn't correctly handle unions, it returns null.

@ostrolucky
Copy link
Contributor Author

Similar issue is for @var non-empty-array<int, string> with error like

Symfony\Component\Serializer\Exception\NotNormalizableValueException : The type of the "slugs" attribute for class "Haushalt\Bl\DomainBundle\Domain\Routing\Entity\RouteInformation" must be one of "Haushalt\Bl\DomainBundle\Domain\Routing\Entity\non-empty-array" ("array" given).

@milikamel
Copy link

no one seems to be interested to reply here!

nicolas-grekas added a commit that referenced this issue Dec 25, 2021
This PR was squashed before being merged into the 5.4 branch.

Discussion
----------

[PropertyInfo] Fix phpstan extractor issues

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #44491
| License       | MIT
| Doc PR        |

Since this crashes denormalization for codebase that was upgraded from 5.3 to 5.4, I am classifying this as a bugfix.

This PR fixes 2 issues. One is with docblocks like `/** `@var` Foo::*|null */`, where Extractor returns `null` only and afterwards Serializer fails to accept anything else. Second is `/** `@var` non-empty-array<...> */` where extractor doesn't recognize that `non-empty-array` is still an array and afterwards Serializer fails complaining that `array` is not an `non-empty-array`

Commits
-------

0302128 [PropertyInfo] Fix phpstan extractor issues
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
0