Code Duplication    Length = 21-22 lines in 7 locations

src/Rules/Comparisons/NumericLessOrEquals.php 1 location

@@ 26-47 (lines=22) @@
23
/**
24
 * @package Limoncello\Validation
25
 */
26
final class NumericLessOrEquals extends BaseOneValueComparision
27
{
28
    /**
29
     * @param mixed $value
30
     */
31
    public function __construct($value)
32
    {
33
        assert(is_numeric($value) === true);
34
        parent::__construct($value, ErrorCodes::NUMERIC_LESS_OR_EQUALS, [ContextKeys::SCALAR_VALUE => $value]);
35
    }
36
37
    /**
38
     * @inheritdoc
39
     */
40
    public static function compare($value, ContextInterface $context): bool
41
    {
42
        assert(is_numeric($value) === true);
43
        $result = is_numeric($value) === true && $value <= static::readValue($context);
44
45
        return $result;
46
    }
47
}
48

src/Rules/Comparisons/NumericLessThan.php 1 location

@@ 26-47 (lines=22) @@
23
/**
24
 * @package Limoncello\Validation
25
 */
26
final class NumericLessThan extends BaseOneValueComparision
27
{
28
    /**
29
     * @param mixed $value
30
     */
31
    public function __construct($value)
32
    {
33
        assert(is_numeric($value) === true);
34
        parent::__construct($value, ErrorCodes::NUMERIC_LESS_THAN, [ContextKeys::SCALAR_VALUE => $value]);
35
    }
36
37
    /**
38
     * @inheritdoc
39
     */
40
    public static function compare($value, ContextInterface $context): bool
41
    {
42
        assert(is_numeric($value) === true);
43
        $result = is_numeric($value) === true && $value < static::readValue($context);
44
45
        return $result;
46
    }
47
}
48

src/Rules/Comparisons/NumericMoreOrEqualsThan.php 1 location

@@ 26-47 (lines=22) @@
23
/**
24
 * @package Limoncello\Validation
25
 */
26
final class NumericMoreOrEqualsThan extends BaseOneValueComparision
27
{
28
    /**
29
     * @param mixed $value
30
     */
31
    public function __construct($value)
32
    {
33
        assert(is_numeric($value) === true);
34
        parent::__construct($value, ErrorCodes::NUMERIC_MORE_OR_EQUALS, [ContextKeys::SCALAR_VALUE => $value]);
35
    }
36
37
    /**
38
     * @inheritdoc
39
     */
40
    public static function compare($value, ContextInterface $context): bool
41
    {
42
        assert(is_numeric($value) === true);
43
        $result = is_numeric($value) === true && static::readValue($context) <= $value;
44
45
        return $result;
46
    }
47
}
48

src/Rules/Comparisons/NumericMoreThan.php 1 location

@@ 26-47 (lines=22) @@
23
/**
24
 * @package Limoncello\Validation
25
 */
26
final class NumericMoreThan extends BaseOneValueComparision
27
{
28
    /**
29
     * @param mixed $value
30
     */
31
    public function __construct($value)
32
    {
33
        assert(is_numeric($value) === true);
34
        parent::__construct($value, ErrorCodes::NUMERIC_MORE_THAN, [ContextKeys::SCALAR_VALUE => $value]);
35
    }
36
37
    /**
38
     * @inheritdoc
39
     */
40
    public static function compare($value, ContextInterface $context): bool
41
    {
42
        assert(is_numeric($value) === true);
43
        $result = is_numeric($value) === true && static::readValue($context) < $value;
44
45
        return $result;
46
    }
47
}
48

src/Rules/Comparisons/StringLengthMax.php 1 location

@@ 26-46 (lines=21) @@
23
/**
24
 * @package Limoncello\Validation
25
 */
26
final class StringLengthMax extends BaseOneValueComparision
27
{
28
    /**
29
     * @param int $max
30
     */
31
    public function __construct(int $max)
32
    {
33
        parent::__construct($max, ErrorCodes::STRING_LENGTH_MAX, [ContextKeys::SCALAR_VALUE => $max]);
34
    }
35
36
    /**
37
     * @inheritdoc
38
     */
39
    public static function compare($value, ContextInterface $context): bool
40
    {
41
        assert(is_string($value) === true);
42
        $result = is_string($value) === true && strlen($value) <= static::readValue($context);
43
44
        return $result;
45
    }
46
}
47

src/Rules/Comparisons/StringLengthMin.php 1 location

@@ 26-46 (lines=21) @@
23
/**
24
 * @package Limoncello\Validation
25
 */
26
final class StringLengthMin extends BaseOneValueComparision
27
{
28
    /**
29
     * @param int $min
30
     */
31
    public function __construct(int $min)
32
    {
33
        parent::__construct($min, ErrorCodes::STRING_LENGTH_MIN, [ContextKeys::SCALAR_VALUE => $min]);
34
    }
35
36
    /**
37
     * @inheritdoc
38
     */
39
    public static function compare($value, ContextInterface $context): bool
40
    {
41
        assert(is_string($value) === true);
42
        $result = is_string($value) === true && static::readValue($context) <= strlen($value);
43
44
        return $result;
45
    }
46
}
47

src/Rules/Comparisons/StringRegExp.php 1 location

@@ 26-47 (lines=22) @@
23
/**
24
 * @package Limoncello\Validation
25
 */
26
final class StringRegExp extends BaseOneValueComparision
27
{
28
    /**
29
     * @param mixed $pattern
30
     */
31
    public function __construct($pattern)
32
    {
33
        assert(is_string($pattern) === true);
34
        parent::__construct($pattern, ErrorCodes::STRING_REG_EXP, [ContextKeys::SCALAR_VALUE => $pattern]);
35
    }
36
37
    /**
38
     * @inheritdoc
39
     */
40
    public static function compare($value, ContextInterface $context): bool
41
    {
42
        assert(is_string($value) === true);
43
        $result = is_string($value) === true && preg_match(static::readValue($context), $value) === 1;
44
45
        return $result;
46
    }
47
}
48