Update Validators to extend ABC instead of implementing interface.
This commit is contained in:
@@ -2,9 +2,14 @@
|
|||||||
|
|
||||||
namespace App\Models\Validation\Validators;
|
namespace App\Models\Validation\Validators;
|
||||||
|
|
||||||
use App\Models\Validation\Validators\ValidationInterface;
|
use App\Models\Validation\Validators\Validator;
|
||||||
|
|
||||||
|
class OkValidator extends Validator {
|
||||||
|
public function isCurrentValid(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
class OkValidator implements ValidationInterface {
|
|
||||||
public function isValid(): bool
|
public function isValid(): bool
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -2,15 +2,14 @@
|
|||||||
|
|
||||||
namespace App\Models\Validation\Validators;
|
namespace App\Models\Validation\Validators;
|
||||||
|
|
||||||
use App\Models\Validation\Validators\ValidationInterface;
|
use App\Models\Validation\Validators\Validator;
|
||||||
use App\Models\Validation\Validators\ValidationTrait;
|
|
||||||
|
|
||||||
class UpperRangeValidator implements ValidationInterface {
|
class UpperRangeValidator extends Validator {
|
||||||
private ValidationInterface $nextValidator;
|
|
||||||
private int $value;
|
private int $value;
|
||||||
private int $rangeLimit;
|
private int $rangeLimit;
|
||||||
|
protected Validator $nextValidator;
|
||||||
|
|
||||||
public function __construct(int $value, int $rangeLimit, ValidationInterface $nextValidator)
|
public function __construct(int $value, int $rangeLimit, Validator $nextValidator)
|
||||||
{
|
{
|
||||||
$this->value = $value;
|
$this->value = $value;
|
||||||
$this->rangeLimit = $rangeLimit;
|
$this->rangeLimit = $rangeLimit;
|
||||||
@@ -24,10 +23,5 @@ class UpperRangeValidator implements ValidationInterface {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isValid(): bool
|
|
||||||
{
|
|
||||||
return $this->isCurrentValid() && $this->nextValidator->isValid();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Validation\Validators;
|
||||||
|
|
||||||
|
abstract class Validator {
|
||||||
|
abstract public function isCurrentValid(): bool;
|
||||||
|
|
||||||
|
public function isValid(): bool
|
||||||
|
{
|
||||||
|
return $this->isCurrentValid() && $this->nextValidator->isValid();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user