ValidatorError::jsonSerialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * @author    Nurlan Mukhanov <[email protected]>
4
 * @copyright 2022 Nurlan Mukhanov
5
 * @license   https://en.wikipedia.org/wiki/MIT_License MIT License
6
 * @link      https://github.com/Falseclock/service-layer
7
 */
8
9
declare(strict_types=1);
10
11
namespace Falseclock\Service\Validation;
12
13
use JsonSerializable;
14
15
final class ValidatorError implements JsonSerializable
16
{
17
    public const FIELD_MESSAGE = "message";
18
    public const FIELD_VALUE = "value";
19
    /** @var string */
20
    protected $message;
21
    /** @var mixed */
22
    protected $value;
23
24
    /**
25
     * ValidatorMessage constructor.
26
     *
27
     * @param string|null $message
28
     * @param mixed $value
29
     */
30
    public function __construct(string $message, $value = null)
31
    {
32
        $this->message = $message;
33
        $this->value = $value;
34
    }
35
36
    /**
37
     * @inheritDoc
38
     */
39
    public function jsonSerialize(): array
40
    {
41
        return [
42
            self::FIELD_MESSAGE => $this->getMessage(),
43
            self::FIELD_VALUE => $this->getValue(),
44
        ];
45
    }
46
47
    /**
48
     * @return string
49
     */
50
    public function getMessage(): string
51
    {
52
        return $this->message;
53
    }
54
55
    /**
56
     * @return mixed
57
     */
58
    public function getValue()
59
    {
60
        return $this->value;
61
    }
62
}
63