Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix validate integer php doc type annotation#57435

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@tei0110
Copy link
Contributor

@tei0110tei0110 commentedOct 18, 2025
edited
Loading

Fix PHPDoc type annotation for validateInteger parameters

This PR fixes a PHPStan error caused by the PHPDoc type annotation added in#56503 for thevalidateInteger() method's$parameters argument.

Problem

The PHPDoc typearray{0: 'strict'} requires the first element to always be present and be the string'strict'. However, the$parameters argument defaults to an empty array[], which causes a PHPStan type mismatch error when the method is called without the strict option.

/** * @param  array{0: 'strict'}  $parameters  // ❌ Requires element 0 to exist */publicfunctionvalidateInteger($attribute,$value,array$parameters = []){if (($parameters[0] ??null) ==='strict') {returnis_int($value);    }returnfilter_var($value,FILTER_VALIDATE_INT) !==false;}

Solution

Changed the PHPDoc type toarray<int, string> to properly reflect that:

  • The array can be empty (default case)
  • When provided, it contains string values at integer keys
  • This aligns with other validation rule parameter types in the codebase
/** * @param  array<int, string>  $parameters  // ✅ Allows empty array */

Benefits

  • Eliminates PHPStan errors for projects using strict type checking
  • Maintains backward compatibility with existing code
  • Consistent with parameter type definitions in other validation methods

Changed from `array{0: 'strict'}` to `array<int, string>` tofix PHPStan errors with empty array default value.
Co-authored-by: Sebastian Hädrich <11225821+shaedrich@users.noreply.github.com>
@tei0110
Copy link
ContributorAuthor

@shaedrich
Thank you for the feedback! I've updated it toarray{0?: 'strict'}.

I initially usedarray<int, string> to match the pattern used in other validation methods in the class, but I agree that the more specific type is better here.

shaedrich reacted with thumbs up emoji

@shaedrich
Copy link
Contributor

Thanks a lot!

tei0110 reacted with thumbs up emoji

@taylorotwelltaylorotwell merged commit760ffd1 intolaravel:12.xOct 18, 2025
64 of 66 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

1 more reviewer

@shaedrichshaedrichshaedrich left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@tei0110@shaedrich@taylorotwell

[8]ページ先頭

©2009-2025 Movatter.jp