Add a validator interface, UpperRangeValidator and OkValidator.
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Validation\Validators;
|
||||
|
||||
use App\Models\Validation\Validators\ValidationInterface;
|
||||
|
||||
class OkValidator implements ValidationInterface {
|
||||
public function isValid(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Validation\Validators;
|
||||
|
||||
use App\Models\Validation\Validators\ValidationInterface;
|
||||
use App\Models\Validation\Validators\ValidationTrait;
|
||||
|
||||
class UpperRangeValidator implements ValidationInterface {
|
||||
private ValidationInterface $nextValidator;
|
||||
private int $value;
|
||||
private int $rangeLimit;
|
||||
|
||||
public function __construct(int $value, int $rangeLimit, ValidationInterface $nextValidator)
|
||||
{
|
||||
$this->value = $value;
|
||||
$this->rangeLimit = $rangeLimit;
|
||||
$this->nextValidator = $nextValidator;
|
||||
}
|
||||
|
||||
public function isCurrentValid(): bool
|
||||
{
|
||||
if($this->value > $this->rangeLimit)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isValid(): bool
|
||||
{
|
||||
return $this->isCurrentValid() && $this->nextValidator->isValid();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Validation\Validators;
|
||||
|
||||
interface ValidationInterface {
|
||||
public function isValid(): bool;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user