Passed
Pull Request — master (#84)
by kenny
02:05
created

AbstractValidator::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 4
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace One\Validator;
4
5
abstract class AbstractValidator
6
{
7
    /**
8
     * value
9
     * @var mixed
10
     */
11
    protected $value;
12
13
    /**
14
     * errorMessage
15
     * @var string|null
16
     */
17
    protected $errorMessage;
18
19
    /**
20
     * Default constructor
21
     * @param mixed $value
22
     * @param string|null $errorMessage
23
     */
24
    public function __construct($value = null, $errorMessage = null)
25
    {
26
        if (! empty($value)) {
27
            $this->value = $value;
28
        }
29
        if (! empty($value)) {
30
            $this->errorMessage = $errorMessage;
31
        }
32
    }
33
34
    /**
35
     * @return mixed
36
     */
37
    public function getValue()
38
    {
39
        return $this->value;
40
    }
41
42
    /**
43
     * @param mixed $value
44
     */
45
    public function setValue($value): self
46
    {
47
        $this->value = $value;
48
49
        return $this;
50
    }
51
52
    /**
53
     * @return mixed
54
     */
55
    public function getErrorMessage()
56
    {
57
        return $this->errorMessage;
58
    }
59
60
    /**
61
     * @param mixed $errorMessage
62
     */
63
    public function setErrorMessage($errorMessage = null): self
64
    {
65
        if (! empty($errorMessage) && is_string($errorMessage)) {
66
            $this->errorMessage = $errorMessage;
67
            return $this;
68
        }
69
        throw new \Exception('Supplied argument must be non empty string', 1);
70
    }
71
72
    /**
73
     * Reset error message
74
     */
75
    public function resetErrorMessage(): self
76
    {
77
        $this->errorMessage = null;
78
79
        return $this;
80
    }
81
}
82