mirror of
https://github.com/Respect/Validation.git
synced 2024-06-27 17:50:13 +02:00
Ensure names are always string
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
parent
64ec329663
commit
167c97bb83
|
@ -26,7 +26,7 @@ abstract class AbstractComposite extends AbstractRule
|
|||
$this->addRules($rule);
|
||||
}
|
||||
|
||||
public function setName($name)
|
||||
public function setName(string $name): Validatable
|
||||
{
|
||||
$parentName = $this->getName();
|
||||
foreach ($this->rules as $rule) {
|
||||
|
|
|
@ -15,6 +15,7 @@ namespace Respect\Validation\Rules;
|
|||
|
||||
use Respect\Validation\Exceptions\ValidationException;
|
||||
use Respect\Validation\Validatable;
|
||||
use function is_scalar;
|
||||
|
||||
abstract class AbstractRelated extends AbstractRule
|
||||
{
|
||||
|
@ -28,9 +29,11 @@ abstract class AbstractRelated extends AbstractRule
|
|||
|
||||
public function __construct($reference, Validatable $validator = null, $mandatory = true)
|
||||
{
|
||||
$this->setName($reference);
|
||||
if ($validator && !$validator->getName()) {
|
||||
$validator->setName($reference);
|
||||
if (is_scalar($reference)) {
|
||||
$this->setName((string) $reference);
|
||||
if ($validator && !$validator->getName()) {
|
||||
$validator->setName((string) $reference);
|
||||
}
|
||||
}
|
||||
|
||||
$this->reference = $reference;
|
||||
|
@ -38,7 +41,7 @@ abstract class AbstractRelated extends AbstractRule
|
|||
$this->mandatory = $mandatory;
|
||||
}
|
||||
|
||||
public function setName($name)
|
||||
public function setName(string $name): Validatable
|
||||
{
|
||||
parent::setName($name);
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ abstract class AbstractRule implements Validatable
|
|||
$this->assert($input);
|
||||
}
|
||||
|
||||
public function getName()
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ abstract class AbstractRule implements Validatable
|
|||
return Factory::getDefaultInstance()->exception($this, $input, $extraParams);
|
||||
}
|
||||
|
||||
public function setName($name)
|
||||
public function setName(string $name): Validatable
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ abstract class AbstractWrapper extends AbstractRule
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setName($name)
|
||||
public function setName(string $name): Validatable
|
||||
{
|
||||
$this->validatable->setName($name);
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ class Not extends AbstractRule
|
|||
$this->rule = $rule;
|
||||
}
|
||||
|
||||
public function setName($name)
|
||||
public function setName(string $name): Validatable
|
||||
{
|
||||
$this->rule->setName($name);
|
||||
|
||||
|
|
|
@ -20,11 +20,11 @@ interface Validatable
|
|||
|
||||
public function check($input): void;
|
||||
|
||||
public function getName();
|
||||
public function getName(): ?string;
|
||||
|
||||
public function reportError($input, array $relatedExceptions = []);
|
||||
|
||||
public function setName($name);
|
||||
public function setName(string $name): Validatable;
|
||||
|
||||
public function setTemplate($template);
|
||||
|
||||
|
|
Loading…
Reference in a new issue