Skip to content

Commit

Permalink
Fix wrong type received by "KeySet" rule
Browse files Browse the repository at this point in the history
I've defined the type that `KeySet` would receive as `Key` because, in
fact, it should only accept `Key` rules.

However, the `Validator::__callStatic()` method (called when you run
`v::key(...)`) will create an instance of itself, not the instance of
`Key`, and that's because you might want to add more rules to the chain.
Knowing that, we did some workaround in which `KeySet` will check if the
given rules are either a `Key` or a `Validator` with only one Key rule.

This commit will replace the type from `Key` to `Validatable`, and let
the implementation deal with the wrong type.
  • Loading branch information
henriquemoody committed Jan 6, 2025
1 parent 294c36f commit 9045f65
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions library/ChainedValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace Respect\Validation;

use finfo;
use Respect\Validation\Rules\Key;

interface ChainedValidator extends Validatable
{
Expand Down Expand Up @@ -199,7 +198,7 @@ public function keyNested(
bool $mandatory = true
): ChainedValidator;

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

public function keyValue(string $comparedKey, string $ruleName, string $baseKey): ChainedValidator;

Expand Down

0 comments on commit 9045f65

Please sign in to comment.