| @@ 30-60 (lines=31) @@ | ||
| 27 | /** |
|
| 28 | * @package Limoncello\Validation |
|
| 29 | */ |
|
| 30 | final class NumericBetween extends BaseTwoValueComparision |
|
| 31 | { |
|
| 32 | /** |
|
| 33 | * @param mixed $lowerValue |
|
| 34 | * @param mixed $upperValue |
|
| 35 | */ |
|
| 36 | public function __construct($lowerValue, $upperValue) |
|
| 37 | { |
|
| 38 | assert(is_numeric($lowerValue) === true && is_numeric($upperValue) === true && $lowerValue <= $upperValue); |
|
| 39 | parent::__construct( |
|
| 40 | $lowerValue, |
|
| 41 | $upperValue, |
|
| 42 | ErrorCodes::NUMERIC_BETWEEN, |
|
| 43 | Messages::NUMERIC_BETWEEN, |
|
| 44 | [$lowerValue, $upperValue] |
|
| 45 | ); |
|
| 46 | } |
|
| 47 | ||
| 48 | /** |
|
| 49 | * @inheritdoc |
|
| 50 | */ |
|
| 51 | public static function compare($value, ContextInterface $context): bool |
|
| 52 | { |
|
| 53 | assert(is_numeric($value) === true); |
|
| 54 | $result = |
|
| 55 | is_numeric($value) === true && |
|
| 56 | static::readLowerValue($context) <= $value && $value <= static::readUpperValue($context); |
|
| 57 | ||
| 58 | return $result; |
|
| 59 | } |
|
| 60 | } |
|
| 61 | ||
| @@ 32-63 (lines=32) @@ | ||
| 29 | /** |
|
| 30 | * @package Limoncello\Validation |
|
| 31 | */ |
|
| 32 | final class StringLengthBetween extends BaseTwoValueComparision |
|
| 33 | { |
|
| 34 | /** |
|
| 35 | * @param int $min |
|
| 36 | * @param int $max |
|
| 37 | */ |
|
| 38 | public function __construct($min, $max) |
|
| 39 | { |
|
| 40 | assert(is_scalar($min) === true && is_scalar($max) === true); |
|
| 41 | parent::__construct( |
|
| 42 | $min, |
|
| 43 | $max, |
|
| 44 | ErrorCodes::STRING_LENGTH_BETWEEN, |
|
| 45 | Messages::STRING_LENGTH_BETWEEN, |
|
| 46 | [$min, $max] |
|
| 47 | ); |
|
| 48 | } |
|
| 49 | ||
| 50 | /** |
|
| 51 | * @inheritdoc |
|
| 52 | */ |
|
| 53 | public static function compare($value, ContextInterface $context): bool |
|
| 54 | { |
|
| 55 | assert(is_string($value) === true); |
|
| 56 | $result = |
|
| 57 | is_string($value) === true && |
|
| 58 | static::readLowerValue($context) <= ($length = strlen($value)) && |
|
| 59 | $length <= static::readUpperValue($context); |
|
| 60 | ||
| 61 | return $result; |
|
| 62 | } |
|
| 63 | } |
|
| 64 | ||