Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[PropertyInfo] Detection of primitive types is broken for classes with docblocks #46383

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 May 17, 2022 · 0 comments

Comments

@ostrolucky
Copy link
Contributor

Symfony version(s) affected

6.1.0

Description

PropertyInfo incorrectly detects collection type for types not documented in docblock since 6.1 version. Deserialization then fails with error

In ArrayDenormalizer.php line 40:
                                                                     
  [Symfony\Component\Serializer\Exception\InvalidArgumentException]  
  Data expected to be an array, int given.                                                                        

This is because before, ConstructorExtractor has been called, but now this is no longer the case. Now, PhpstanExtractor is called, which resolves types documented in phpdoc only. I've checked a bit why is this the case and looks like on 6.0, this line is triggered

, while on 6.1 it isn't. But looks like real issue is that PhpStanExtractor is not returning null in getDocBlockFromProperty for such (non-documented) properties.

How to reproduce

deserialize

{"id": 1, "variations": []}

into

namespace Haushalt\Bl\DomainBundle\Domain\Product\Entity;

final class Product
{
    /**
     * @param \stdClass[]   $variations
     */
    public function __construct(
        public int $id,
        public array $variations,
    ) {
    }

    public function getId(): int
    {
        return $this->id;
    }
}

Possible Solution

No response

Additional Context

No response

@ostrolucky ostrolucky added the Bug label May 17, 2022
@fabpot fabpot closed this as completed May 27, 2022
fabpot added a commit that referenced this issue May 27, 2022
…d constructors (ostrolucky)

This PR was merged into the 6.1 branch.

Discussion
----------

[PropertyInfo] Fix resolution of partially docblock covered constructors

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

This fixes a regression in 6.1

Commits
-------

dc4bca8 [PropertyInfo] Fix resolution of partially docblock covered constructors
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

3 participants