ValidationException::jsonSerialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
/**
3
 * @author Todd Burry <[email protected]>
4
 * @copyright 2009-2018 Vanilla Forums Inc.
5
 * @license MIT
6
 */
7
8
namespace Garden\Schema;
9
10
/**
11
 * An exception that was built from a {@link Validation} object.
12
 *
13
 * The validation object collects errors and is mutable. Once it's ready to be thrown as an exception it gets converted
14
 * to an instance of the immutable {@link ValidationException} class.
15
 */
16
class ValidationException extends \Exception implements \JsonSerializable {
17
    /**
18
     * @var Validation
19
     */
20
    private $validation;
21
22
    /**
23
     * Initialize an instance of the {@link ValidationException} class.
24
     *
25
     * @param Validation $validation The {@link Validation} object for the exception.
26
     */
27 82
    public function __construct(Validation $validation) {
28 82
        $this->validation = $validation;
29 82
        parent::__construct($validation->getFullMessage(), $validation->getCode());
30 82
    }
31
32
    /**
33
     * Specify data which should be serialized to JSON.
34
     *
35
     * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
36
     * @return mixed data which can be serialized by <b>json_encode</b>,
37
     * which is a value of any type other than a resource.
38
     */
39
    public function jsonSerialize() {
40
        return $this->validation->jsonSerialize();
41
    }
42
43
    /**
44
     * Get the validation object that contain specific errors.
45
     *
46
     * @return Validation Returns a validation object.
47
     */
48 39
    public function getValidation() {
49 39
        return $this->validation;
50
    }
51
}
52