| @@ 19-56 (lines=38) @@ | ||
| 16 | /** |
|
| 17 | * Check maximum length. |
|
| 18 | */ |
|
| 19 | class MaxLength implements RuleInterface |
|
| 20 | { |
|
| 21 | /** |
|
| 22 | * @var string Received value. |
|
| 23 | */ |
|
| 24 | private $received; |
|
| 25 | ||
| 26 | /** |
|
| 27 | * @var int Max allowed length. |
|
| 28 | */ |
|
| 29 | private $maxLength; |
|
| 30 | ||
| 31 | /** |
|
| 32 | * Class constructor. |
|
| 33 | * |
|
| 34 | * @param string $received |
|
| 35 | * @param int $maxLength |
|
| 36 | */ |
|
| 37 | public function __construct(string $received, int $maxLength) |
|
| 38 | { |
|
| 39 | $this->received = $received; |
|
| 40 | $this->maxLength = $maxLength; |
|
| 41 | } |
|
| 42 | ||
| 43 | /** |
|
| 44 | * Test. |
|
| 45 | * |
|
| 46 | * @return bool |
|
| 47 | */ |
|
| 48 | public function test(): bool |
|
| 49 | { |
|
| 50 | if (strlen($this->received) > $this->maxLength) { |
|
| 51 | return true; |
|
| 52 | } |
|
| 53 | ||
| 54 | return false; |
|
| 55 | } |
|
| 56 | } |
|
| 57 | ||
| @@ 19-56 (lines=38) @@ | ||
| 16 | /** |
|
| 17 | * Check maximum length. |
|
| 18 | */ |
|
| 19 | class MinLength implements RuleInterface |
|
| 20 | { |
|
| 21 | /** |
|
| 22 | * @var string Received value. |
|
| 23 | */ |
|
| 24 | private $received; |
|
| 25 | ||
| 26 | /** |
|
| 27 | * @var int Min allowed length. |
|
| 28 | */ |
|
| 29 | private $minLength; |
|
| 30 | ||
| 31 | /** |
|
| 32 | * Class constructor. |
|
| 33 | * |
|
| 34 | * @param string $received |
|
| 35 | * @param int $minLength |
|
| 36 | */ |
|
| 37 | public function __construct(string $received, int $minLength) |
|
| 38 | { |
|
| 39 | $this->received = $received; |
|
| 40 | $this->minLength = $minLength; |
|
| 41 | } |
|
| 42 | ||
| 43 | /** |
|
| 44 | * Test. |
|
| 45 | * |
|
| 46 | * @return bool |
|
| 47 | */ |
|
| 48 | public function test(): bool |
|
| 49 | { |
|
| 50 | if (strlen($this->received) > $this->minLength) { |
|
| 51 | return true; |
|
| 52 | } |
|
| 53 | ||
| 54 | return false; |
|
| 55 | } |
|
| 56 | } |
|
| 57 | ||