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

Skip to content

Count constraint docblock causes psalm and phpstan fail on max 0 value #59307

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
aguerre opened this issue Dec 27, 2024 · 1 comment
Closed

Comments

@aguerre
Copy link

aguerre commented Dec 27, 2024

Symfony version(s) affected

7.2.0

Description

This PR #58049 affected psalm and phpstan validation on Count constraint use:

ERROR: InvalidArgument - src/XXXX/Model/MyModel.php:44:31 - Argument 1 of Symfony\Component\Validator\Constraints\Count::__construct expects int<1, max>|null, but 0 provided (see https://psalm.dev/004)
        new Assert\Count(max: 0),

With

    #[Assert\AtLeastOneOf([
        new Assert\Count(max: 0),
        new Assert\IsNull(),
        new AppAssert\IsValidSignature(),
    ])]
    private ?array $signature = [];

My $signature is an array of coordinates and can be empty for some frontend reasons.

How to reproduce

Use Count constraint with max : 0

Possible Solution

Change @param max dockblock to accept zero

Additional Context

No response

@xabbuh
Copy link
Member

xabbuh commented Dec 27, 2024

see #59310

GromNaN added a commit that referenced this issue Dec 27, 2024
This PR was merged into the 7.2 branch.

Discussion
----------

[Validator] the "max" option can be zero

| Q             | A
| ------------- | ---
| Branch?       | 7.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #59307
| License       | MIT

Commits
-------

a5d95be the "max" option can be zero
@xabbuh xabbuh closed this as completed Dec 27, 2024
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