Completed
Pull Request — master (#237)
by Théo
04:25 queued 01:49
created

JsonValidationException::createDecodeException()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 23
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
c 0
b 0
f 0
rs 8.5906
cc 6
eloc 19
nc 6
nop 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A JsonValidationException::getErrors() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the box project.
7
 *
8
 * (c) Kevin Herrera <[email protected]>
9
 *     Théo Fidry <[email protected]>
10
 *
11
 * This source file is subject to the MIT license that is bundled
12
 * with this source code in the file LICENSE.
13
 */
14
15
namespace KevinGH\Box\Json;
16
17
use Assert\Assertion;
18
use Throwable;
19
use UnexpectedValueException;
20
21
/**
22
 * @private
23
 */
24
final class JsonValidationException extends UnexpectedValueException
25
{
26
    private $validatedFile;
27
    private $errors;
28
29
    /**
30
     * {@inheritdoc}
31
     *
32
     * @param string[] $errors
33
     */
34
    public function __construct(
35
        string $message,
36
        string $file = null,
37
        array $errors = [],
38
        int $code = 0,
39
        Throwable $previous = null
40
    ) {
41
        if (null !== $file) {
42
            Assertion::file($file);
43
        }
44
        Assertion::allString($errors);
45
46
        $this->validatedFile = $file;
47
        $this->errors = $errors;
48
49
        parent::__construct($message, $code, $previous);
50
    }
51
52
    public function getValidatedFile(): ?string
53
    {
54
        return $this->validatedFile;
55
    }
56
57
    /**
58
     * @return string[]
59
     */
60
    public function getErrors(): array
61
    {
62
        return $this->errors;
63
    }
64
}
65