Code Duplication    Length = 25-25 lines in 6 locations

src/Rules/Comparisons/DateTimeEquals.php 1 location

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

src/Rules/Comparisons/DateTimeLessOrEquals.php 1 location

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

src/Rules/Comparisons/DateTimeLessThan.php 1 location

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

src/Rules/Comparisons/DateTimeMoreOrEquals.php 1 location

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

src/Rules/Comparisons/DateTimeMoreThan.php 1 location

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

src/Rules/Comparisons/DateTimeNotEquals.php 1 location

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