Completed
Push — master ( 984d76...8152ca )
by WEBEWEB
04:38
created

AbstractValidationStatus::setMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the core-library package.
5
 *
6
 * (c) 2018 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Library\Core\Validator\Status;
13
14
use JsonSerializable;
15
use WBW\Library\Core\Validator\API\ValidationStatusInterface;
16
17
/**
18
 * Abstract validation status.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Library\Core\Validator\Status
22
 * @abstract
23
 */
24
abstract class AbstractValidationStatus implements JsonSerializable, ValidationStatusInterface {
25
26
    /**
27
     * Get the code.
28
     *
29
     * @var int
30
     */
31
    private $code;
32
33
    /**
34
     * Message.
35
     *
36
     * @var string
37
     */
38
    private $message;
39
40
    /**
41
     * Rule name.
42
     *
43
     * @var string
44
     */
45
    private $ruleName;
46
47
    /**
48
     * Constructor.
49
     *
50
     * @param int $code The code.
51
     * @param string $message The message.
52
     */
53
    protected function __construct($code, $message) {
54
        $this->setCode($code);
55
        $this->setMessage($message);
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function getCode() {
62
        return $this->code;
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function getMessage() {
69
        return $this->message;
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function getRuleName() {
76
        return $this->ruleName;
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82
    public function jsonSerialize() {
83
        return [
84
            "code"     => $this->getCode(),
85
            "message"  => $this->getMessage(),
86
            "ruleName" => $this->getRuleName(),
87
        ];
88
    }
89
90
    /**
91
     * Set the code.
92
     *
93
     * @param int $code The code.
94
     * @return ValidationStatusInterface Returns this validation status.
95
     */
96
    public function setCode($code) {
97
        $this->code = $code;
98
        return $this;
99
    }
100
101
    /**
102
     * Set the message.
103
     *
104
     * @param string $message The message.
105
     * @return ValidationStatusInterface Returns this validation status.
106
     */
107
    public function setMessage($message) {
108
        $this->message = $message;
109
        return $this;
110
    }
111
112
    /**
113
     * {@inheritdoc}
114
     */
115
    public function setRuleName($ruleName) {
116
        $this->ruleName = $ruleName;
117
        return $this;
118
    }
119
}
120