Skip to content

Commit 8dfa487

Browse files
committed
Prevent validators from generating validatorBuilder Ids
When calling `v::validatorName()`, a `ValidatorBuilder` is instantiated to manage the validation chain. However, users generally expect the ID to reflect the specific validator invoked rather than the internal builder class. This commit updates `Id::fromValidator()` to resolve the ID from the underlying validator when it is the sole member of the `ValidatorBuilder`, ensuring more intuitive identification.
1 parent 9e768cc commit 8dfa487

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

library/Id.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace Respect\Validation;
1111

12+
use function count;
1213
use function lcfirst;
1314
use function strrchr;
1415
use function substr;
@@ -23,6 +24,10 @@ public function __construct(
2324

2425
public static function fromValidator(Validator $validator): self
2526
{
27+
if ($validator instanceof ValidatorBuilder && count($validator->getValidators()) === 1) {
28+
return self::fromValidator($validator->getValidators()[0]);
29+
}
30+
2631
return new self(lcfirst(substr((string) strrchr($validator::class, '\\'), 1)));
2732
}
2833

0 commit comments

Comments
 (0)