Skip to content
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

Issue with Typing in keySet and key Methods #1497

Open
agchan12 opened this issue Dec 17, 2024 · 0 comments
Open

Issue with Typing in keySet and key Methods #1497

agchan12 opened this issue Dec 17, 2024 · 0 comments

Comments

@agchan12
Copy link

agchan12 commented Dec 17, 2024

Problem Description

There is a typing mismatch in the keySet method that causes PHPStan (our static analysis tool) to flag its usage as invalid typing, even though it works at runtime.

The docs do recommend provide the following usage examples.

$dict = ['foo' => 42];

v::keySet(
    v::key('foo', v::intVal())
)->validate($dict); // true

So I am just looking for guidance here.

Specifically:

The keySet method is typed as accepting Key ...$rule.

public static function keySet(Key ...$rule): ChainedValidator;

The key method, often used with keySet, returns a ChainedValidator

public static function key(
    string $reference,
    ?Validatable $referenceValidator = null,
    bool $mandatory = true
): ChainedValidator;

This creates an issue with PHPStan because keySet expects Key objects, but key returns a ChainedValidator.

This is more a question to see where your thoughts are at with this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant