Code Duplication    Length = 58-65 lines in 2 locations

src/Validator/Page.php 1 location

@@ 25-89 (lines=65) @@
22
 * @package TxTextControl\ReportingCloud
23
 * @author  Jonathan Maron (@JonathanMaron)
24
 */
25
class Page extends AbstractValidator
26
{
27
    /**
28
     * Minimum page number
29
     *
30
     * @const MIN
31
     */
32
    const MIN = 1;
33
    /**
34
     * Invalid type
35
     *
36
     * @const INVALID_TYPE
37
     */
38
    const INVALID_TYPE = 'invalidType';
39
    /**
40
     * Invalid page
41
     *
42
     * @const INVALID_INTEGER
43
     */
44
    const INVALID_INTEGER = 'invalidInteger';
45
46
    /**
47
     * Message templates
48
     *
49
     * @var array
50
     */
51
    protected $messageTemplates = [
52
        self::INVALID_TYPE    => "'%value%' must be an integer",
53
        self::INVALID_INTEGER => "'%value%' contains an invalid page number",
54
    ];
55
56
    /**
57
     * Returns true, if value is valid. False otherwise.
58
     *
59
     * @param mixed $value
60
     *
61
     * @return bool
62
     */
63
    public function isValid($value)
64
    {
65
        $this->setValue($value);
66
67
        $typeIntegerValidator = new TypeIntegerValidator();
68
69
        if (!$typeIntegerValidator->isValid($value)) {
70
            $this->error(self::INVALID_TYPE);
71
72
            return false;
73
        }
74
75
        $greaterThanValidator = new GreaterThanValidator([
76
            'min'       => self::MIN,
77
            'inclusive' => true,
78
        ]);
79
80
        if (!$greaterThanValidator->isValid($value)) {
81
            $this->error(self::INVALID_INTEGER);
82
83
            return false;
84
        }
85
86
        return true;
87
    }
88
}

src/Validator/Timestamp.php 1 location

@@ 25-82 (lines=58) @@
22
 * @package TxTextControl\ReportingCloud
23
 * @author  Jonathan Maron (@JonathanMaron)
24
 */
25
class Timestamp extends AbstractValidator
26
{
27
    /**
28
     * Invalid type
29
     *
30
     * @const INVALID_TYPE
31
     */
32
    const INVALID_TYPE = 'invalidType';
33
    /**
34
     * Invalid range
35
     *
36
     * @const INVALID_RANGE
37
     */
38
    const INVALID_RANGE = 'invalidRange';
39
40
    /**
41
     * Message templates
42
     *
43
     * @var array
44
     */
45
    protected $messageTemplates = [
46
        self::INVALID_TYPE  => "'%value%' must be an integer",
47
        self::INVALID_RANGE => "'%value%' is not in the required range",
48
    ];
49
50
    /**
51
     * Returns true, if value is valid. False otherwise.
52
     *
53
     * @param mixed $value
54
     *
55
     * @return bool
56
     */
57
    public function isValid($value)
58
    {
59
        $this->setValue($value);
60
61
        $typeIntegerValidator = new TypeIntegerValidator();
62
63
        if (!$typeIntegerValidator->isValid($value)) {
64
            $this->error(self::INVALID_TYPE);
65
66
            return false;
67
        }
68
69
        $betweenValidator = new BetweenValidator([
70
            'min'       => 0,
71
            'max'       => PHP_INT_MAX,
72
            'inclusive' => true,
73
        ]);
74
75
        if (!$betweenValidator->isValid($value)) {
76
            $this->error(self::INVALID_RANGE);
77
78
            return false;
79
        }
80
81
        return true;
82
    }
83
}
84