Skip to content

Conversation

@tei0110
Copy link
Contributor

@tei0110 tei0110 commented Oct 18, 2025

Fix PHPDoc type annotation for validateInteger parameters

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

Problem

The PHPDoc type array{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  */ public function validateInteger($attribute, $value, array $parameters = []) { if (($parameters[0] ?? null) === 'strict') { return is_int($value); } return filter_var($value, FILTER_VALIDATE_INT) !== false; }

Solution

Changed the PHPDoc type to array<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>` to fix PHPStan errors with empty array default value.
Co-authored-by: Sebastian Hädrich <11225821+shaedrich@users.noreply.github.com>
@tei0110
Copy link
Contributor Author

tei0110 commented Oct 18, 2025

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

I initially used array<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
Copy link
Contributor

Thanks a lot!

@taylorotwell taylorotwell merged commit 760ffd1 into laravel:12.x Oct 18, 2025
64 of 66 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants