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:
Henrique Moody 2018-08-02 11:13:48 +02:00
parent a1bc0cd6b4
commit afab4eb2b4
No known key found for this signature in database
GPG key ID: 221E9281655813A6
17 changed files with 34 additions and 34 deletions

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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()

View file

@ -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);
}
}
}

View file

@ -64,7 +64,7 @@ abstract class AbstractRelated extends AbstractRule
} catch (ValidationException $e) {
throw $this
->reportError($this->reference, ['hasReference' => true])
->addRelated($e);
->addChild($e);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -95,7 +95,7 @@ class Domain extends AbstractComposite
}
if (count($e)) {
throw $this->reportError($input)->setRelated($e);
throw $this->reportError($input)->addChildren($e);
}
}

View file

@ -63,7 +63,7 @@ final class Each extends AbstractRule
}
if (!empty($exceptions)) {
throw $this->reportError($input)->setRelated($exceptions);
throw $this->reportError($input)->addChildren($exceptions);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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

View file

@ -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;

View file

@ -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';

View file

@ -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';

View file

@ -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());
}
}