mirror of
https://github.com/Respect/Validation.git
synced 2024-06-04 14:52:17 +02:00
Rename "Related" to "Child"
The "NestedValidationException" has exceptions that are its children. However, we call them "related". This commit updates the term over the library. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
parent
a1bc0cd6b4
commit
afab4eb2b4
|
@ -32,7 +32,7 @@ class GroupedValidationException extends NestedValidationException
|
|||
protected function chooseTemplate(): string
|
||||
{
|
||||
$numRules = $this->getParam('passed');
|
||||
$numFailed = $this->getRelated()->count();
|
||||
$numFailed = $this->getChildren()->count();
|
||||
|
||||
return $numRules === $numFailed ? static::NONE : static::SOME;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ class KeySetException extends GroupedValidationException implements NonOmissible
|
|||
*/
|
||||
protected function chooseTemplate(): string
|
||||
{
|
||||
if (0 === $this->getRelated()->count()) {
|
||||
if (0 === $this->getChildren()->count()) {
|
||||
return static::STRUCTURE;
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ class NestedValidationException extends ValidationException implements IteratorA
|
|||
*
|
||||
* @return SplObjectStorage|ValidationException[]
|
||||
*/
|
||||
public function getRelated(): SplObjectStorage
|
||||
public function getChildren(): SplObjectStorage
|
||||
{
|
||||
if (!$this->exceptions instanceof SplObjectStorage) {
|
||||
$this->exceptions = new SplObjectStorage();
|
||||
|
@ -62,9 +62,9 @@ class NestedValidationException extends ValidationException implements IteratorA
|
|||
*
|
||||
* @return self
|
||||
*/
|
||||
public function addRelated(ValidationException $exception): self
|
||||
public function addChild(ValidationException $exception): self
|
||||
{
|
||||
$this->getRelated()->attach($exception);
|
||||
$this->getChildren()->attach($exception);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -76,10 +76,10 @@ class NestedValidationException extends ValidationException implements IteratorA
|
|||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setRelated(array $exceptions): self
|
||||
public function addChildren(array $exceptions): self
|
||||
{
|
||||
foreach ($exceptions as $exception) {
|
||||
$this->addRelated($exception);
|
||||
$this->addChild($exception);
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
@ -139,7 +139,7 @@ class NestedValidationException extends ValidationException implements IteratorA
|
|||
public function getMessages(array $templates = []): array
|
||||
{
|
||||
$messages = [$this->getId() => $this->renderMessage($this, $templates)];
|
||||
foreach ($this->getRelated() as $exception) {
|
||||
foreach ($this->getChildren() as $exception) {
|
||||
$id = $exception->getId();
|
||||
if (!$exception instanceof self) {
|
||||
$messages[$id] = $this->renderMessage(
|
||||
|
@ -205,12 +205,12 @@ class NestedValidationException extends ValidationException implements IteratorA
|
|||
return false;
|
||||
}
|
||||
|
||||
if (1 !== $exception->getRelated()->count()) {
|
||||
if (1 !== $exception->getChildren()->count()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$exception->getRelated()->rewind();
|
||||
$childException = $exception->getRelated()->current();
|
||||
$exception->getChildren()->rewind();
|
||||
$childException = $exception->getChildren()->current();
|
||||
if ($childException->getMessage() === $exception->getMessage()) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ class RecursiveExceptionIterator implements RecursiveIterator, Countable
|
|||
|
||||
public function __construct(NestedValidationException $parent)
|
||||
{
|
||||
$this->exceptions = $parent->getRelated();
|
||||
$this->exceptions = $parent->getChildren();
|
||||
}
|
||||
|
||||
public function count()
|
||||
|
|
|
@ -137,8 +137,8 @@ abstract class AbstractComposite extends AbstractRule
|
|||
return;
|
||||
}
|
||||
|
||||
foreach ($exception->getRelated() as $relatedException) {
|
||||
$this->updateExceptionTemplate($relatedException);
|
||||
foreach ($exception->getChildren() as $childException) {
|
||||
$this->updateExceptionTemplate($childException);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ abstract class AbstractRelated extends AbstractRule
|
|||
} catch (ValidationException $e) {
|
||||
throw $this
|
||||
->reportError($this->reference, ['hasReference' => true])
|
||||
->addRelated($e);
|
||||
->addChild($e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ class AllOf extends AbstractComposite
|
|||
'passed' => $numRules - $numExceptions,
|
||||
];
|
||||
if (!empty($exceptions)) {
|
||||
throw $this->reportError($input, $summary)->setRelated($exceptions);
|
||||
throw $this->reportError($input, $summary)->addChildren($exceptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ class AnyOf extends AbstractComposite
|
|||
$numRules = count($validators);
|
||||
$numExceptions = count($exceptions);
|
||||
if ($numExceptions === $numRules) {
|
||||
throw $this->reportError($input)->setRelated($exceptions);
|
||||
throw $this->reportError($input)->addChildren($exceptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ class Domain extends AbstractComposite
|
|||
}
|
||||
|
||||
if (count($e)) {
|
||||
throw $this->reportError($input)->setRelated($e);
|
||||
throw $this->reportError($input)->addChildren($e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ final class Each extends AbstractRule
|
|||
}
|
||||
|
||||
if (!empty($exceptions)) {
|
||||
throw $this->reportError($input)->setRelated($exceptions);
|
||||
throw $this->reportError($input)->addChildren($exceptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ class NoneOf extends AbstractComposite
|
|||
$numRules = count($this->getRules());
|
||||
$numExceptions = count($exceptions);
|
||||
if ($numRules !== $numExceptions) {
|
||||
throw $this->reportError($input)->setRelated($exceptions);
|
||||
throw $this->reportError($input)->addChildren($exceptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ class OneOf extends AbstractComposite
|
|||
$numRules = count($validators);
|
||||
$numExceptions = count($exceptions);
|
||||
if ($numExceptions !== $numRules - 1) {
|
||||
throw $this->reportError($input)->setRelated($exceptions);
|
||||
throw $this->reportError($input)->addChildren($exceptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ class Zend extends AbstractRule
|
|||
$exceptions[] = $this->reportError($m, get_object_vars($this));
|
||||
}
|
||||
|
||||
throw $this->reportError($input)->setRelated($exceptions);
|
||||
throw $this->reportError($input)->addChildren($exceptions);
|
||||
}
|
||||
|
||||
public function validate($input): bool
|
||||
|
|
|
@ -24,7 +24,7 @@ interface Validatable
|
|||
|
||||
public function getName(): ?string;
|
||||
|
||||
public function reportError($input, array $relatedExceptions = []): ValidationException;
|
||||
public function reportError($input, array $extraParameters = []): ValidationException;
|
||||
|
||||
public function setName(string $name): Validatable;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
--TEST--
|
||||
not() with recursion should update mode from related rules
|
||||
not() with recursion should update mode of its children
|
||||
--FILE--
|
||||
<?php
|
||||
require 'vendor/autoload.php';
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
--TEST--
|
||||
not() with recursion should update mode from related rules
|
||||
not() with recursion should update mode of its children
|
||||
--FILE--
|
||||
<?php
|
||||
require 'vendor/autoload.php';
|
||||
|
|
|
@ -23,13 +23,13 @@ class NestedValidationExceptionTest extends TestCase
|
|||
/**
|
||||
* @test
|
||||
*/
|
||||
public function getRelatedShouldReturnExceptionAddedByAddRelated(): void
|
||||
public function getChildrenShouldReturnExceptionAddedByAddRelated(): void
|
||||
{
|
||||
$composite = new AttributeException('input', 'id', [], 'trim');
|
||||
$node = new IntValException('input', 'id', [], 'trim');
|
||||
$composite->addRelated($node);
|
||||
self::assertCount(1, $composite->getRelated(true));
|
||||
self::assertContainsOnly($node, $composite->getRelated());
|
||||
$composite->addChild($node);
|
||||
self::assertCount(1, $composite->getChildren(true));
|
||||
self::assertContainsOnly($node, $composite->getChildren());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,10 +39,10 @@ class NestedValidationExceptionTest extends TestCase
|
|||
{
|
||||
$composite = new AttributeException('input', 'id', [], 'trim');
|
||||
$node = new IntValException('input', 'id', [], 'trim');
|
||||
$composite->addRelated($node);
|
||||
$composite->addRelated($node);
|
||||
$composite->addRelated($node);
|
||||
self::assertCount(1, $composite->getRelated(true));
|
||||
self::assertContainsOnly($node, $composite->getRelated());
|
||||
$composite->addChild($node);
|
||||
$composite->addChild($node);
|
||||
$composite->addChild($node);
|
||||
self::assertCount(1, $composite->getChildren(true));
|
||||
self::assertContainsOnly($node, $composite->getChildren());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue