Skip to content

Commit 9045f65

Browse files
committed
Fix wrong type received by "KeySet" rule
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.
1 parent 294c36f commit 9045f65

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

library/ChainedValidator.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
namespace Respect\Validation;
1111

1212
use finfo;
13-
use Respect\Validation\Rules\Key;
1413

1514
interface ChainedValidator extends Validatable
1615
{
@@ -199,7 +198,7 @@ public function keyNested(
199198
bool $mandatory = true
200199
): ChainedValidator;
201200

202-
public function keySet(Key ...$rule): ChainedValidator;
201+
public function keySet(Validatable ...$rule): ChainedValidator;
203202

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

0 commit comments

Comments
 (0)