Code Duplication    Length = 26-26 lines in 6 locations

src/Rules/Comparisons/DateTimeEquals.php 1 location

@@ 30-55 (lines=26) @@
27
/**
28
 * @package Limoncello\Validation
29
 */
30
final class DateTimeEquals extends BaseOneValueComparision
31
{
32
    /**
33
     * @param DateTimeInterface $value
34
     */
35
    public function __construct(DateTimeInterface $value)
36
    {
37
        parent::__construct(
38
            $value->getTimestamp(),
39
            ErrorCodes::DATE_TIME_EQUALS,
40
            Messages::DATE_TIME_EQUALS,
41
            [$value->getTimestamp()]
42
        );
43
    }
44
45
    /**
46
     * @inheritdoc
47
     */
48
    public static function compare($value, ContextInterface $context): bool
49
    {
50
        assert($value instanceof DateTimeInterface);
51
        $result = $value instanceof DateTimeInterface && $value->getTimestamp() === static::readValue($context);
52
53
        return $result;
54
    }
55
}
56

src/Rules/Comparisons/DateTimeLessOrEquals.php 1 location

@@ 30-55 (lines=26) @@
27
/**
28
 * @package Limoncello\Validation
29
 */
30
final class DateTimeLessOrEquals extends BaseOneValueComparision
31
{
32
    /**
33
     * @param DateTimeInterface $value
34
     */
35
    public function __construct(DateTimeInterface $value)
36
    {
37
        parent::__construct(
38
            $value->getTimestamp(),
39
            ErrorCodes::DATE_TIME_LESS_OR_EQUALS,
40
            Messages::DATE_TIME_LESS_OR_EQUALS,
41
            [$value->getTimestamp()]
42
        );
43
    }
44
45
    /**
46
     * @inheritdoc
47
     */
48
    public static function compare($value, ContextInterface $context): bool
49
    {
50
        assert($value instanceof DateTimeInterface);
51
        $result = $value instanceof DateTimeInterface && $value->getTimestamp() <= static::readValue($context);
52
53
        return $result;
54
    }
55
}
56

src/Rules/Comparisons/DateTimeLessThan.php 1 location

@@ 30-55 (lines=26) @@
27
/**
28
 * @package Limoncello\Validation
29
 */
30
final class DateTimeLessThan extends BaseOneValueComparision
31
{
32
    /**
33
     * @param DateTimeInterface $value
34
     */
35
    public function __construct(DateTimeInterface $value)
36
    {
37
        parent::__construct(
38
            $value->getTimestamp(),
39
            ErrorCodes::DATE_TIME_LESS_THAN,
40
            Messages::DATE_TIME_LESS_THAN,
41
            [$value->getTimestamp()]
42
        );
43
    }
44
45
    /**
46
     * @inheritdoc
47
     */
48
    public static function compare($value, ContextInterface $context): bool
49
    {
50
        assert($value instanceof DateTimeInterface);
51
        $result = $value instanceof DateTimeInterface && $value->getTimestamp() < static::readValue($context);
52
53
        return $result;
54
    }
55
}
56

src/Rules/Comparisons/DateTimeMoreOrEquals.php 1 location

@@ 30-55 (lines=26) @@
27
/**
28
 * @package Limoncello\Validation
29
 */
30
final class DateTimeMoreOrEquals extends BaseOneValueComparision
31
{
32
    /**
33
     * @param DateTimeInterface $value
34
     */
35
    public function __construct(DateTimeInterface $value)
36
    {
37
        parent::__construct(
38
            $value->getTimestamp(),
39
            ErrorCodes::DATE_TIME_MORE_OR_EQUALS,
40
            Messages::DATE_TIME_MORE_OR_EQUALS,
41
            [$value->getTimestamp()]
42
        );
43
    }
44
45
    /**
46
     * @inheritdoc
47
     */
48
    public static function compare($value, ContextInterface $context): bool
49
    {
50
        assert($value instanceof DateTimeInterface);
51
        $result = $value instanceof DateTimeInterface && static::readValue($context) <= $value->getTimestamp();
52
53
        return $result;
54
    }
55
}
56

src/Rules/Comparisons/DateTimeMoreThan.php 1 location

@@ 30-55 (lines=26) @@
27
/**
28
 * @package Limoncello\Validation
29
 */
30
final class DateTimeMoreThan extends BaseOneValueComparision
31
{
32
    /**
33
     * @param DateTimeInterface $value
34
     */
35
    public function __construct(DateTimeInterface $value)
36
    {
37
        parent::__construct(
38
            $value->getTimestamp(),
39
            ErrorCodes::DATE_TIME_MORE_THAN,
40
            Messages::DATE_TIME_MORE_THAN,
41
            [$value->getTimestamp()]
42
        );
43
    }
44
45
    /**
46
     * @inheritdoc
47
     */
48
    public static function compare($value, ContextInterface $context): bool
49
    {
50
        assert($value instanceof DateTimeInterface);
51
        $result = $value instanceof DateTimeInterface && static::readValue($context) < $value->getTimestamp();
52
53
        return $result;
54
    }
55
}
56

src/Rules/Comparisons/DateTimeNotEquals.php 1 location

@@ 30-55 (lines=26) @@
27
/**
28
 * @package Limoncello\Validation
29
 */
30
final class DateTimeNotEquals extends BaseOneValueComparision
31
{
32
    /**
33
     * @param DateTimeInterface $value
34
     */
35
    public function __construct(DateTimeInterface $value)
36
    {
37
        parent::__construct(
38
            $value->getTimestamp(),
39
            ErrorCodes::DATE_TIME_NOT_EQUALS,
40
            Messages::DATE_TIME_NOT_EQUALS,
41
            [$value->getTimestamp()]
42
        );
43
    }
44
45
    /**
46
     * @inheritdoc
47
     */
48
    public static function compare($value, ContextInterface $context): bool
49
    {
50
        assert($value instanceof DateTimeInterface);
51
        $result = $value instanceof DateTimeInterface && $value->getTimestamp() !== static::readValue($context);
52
53
        return $result;
54
    }
55
}
56