Completed
Push — master ( 9cc31a...349e87 )
by WEBEWEB
01:54
created

AbstractValidationStatus::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\Validation\Status;
13
14
use JsonSerializable;
15
use WBW\Library\Core\Validation\API\ValidationStatusInterface;
16
17
/**
18
 * Abstract validation status.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Library\Core\Validation\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 $this->toArray();
84
    }
85
86
    /**
87
     * Set the code.
88
     *
89
     * @param int $code The code.
90
     * @return ValidationStatusInterface Returns this validation status.
91
     */
92
    public function setCode($code) {
93
        $this->code = $code;
94
        return $this;
95
    }
96
97
    /**
98
     * Set the message.
99
     *
100
     * @param string $message The message.
101
     * @return ValidationStatusInterface Returns this validation status.
102
     */
103
    public function setMessage($message) {
104
        $this->message = $message;
105
        return $this;
106
    }
107
108
    /**
109
     * {@inheritdoc}
110
     */
111
    public function setRuleName($ruleName) {
112
        $this->ruleName = $ruleName;
113
        return $this;
114
    }
115
116
    /**
117
     * Convert into an array representing this instance.
118
     *
119
     * @return array Returns an array representing this instance.
120
     */
121
    public function toArray() {
122
123
        // Initialize the output.
124
        $output = [];
125
126
        $output["code"]     = $this->code;
127
        $output["message"]  = $this->message;
128
        $output["ruleName"] = $this->ruleName;
129
130
        // Return the output.
131
        return $output;
132
    }
133
134
}
135