Issues (224)

src/Json/JsonValidationException.php (2 issues)

Labels
Severity
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 Throwable;
18
use UnexpectedValueException;
19
use Webmozart\Assert\Assert;
20
21
/**
22
 * @private
23
 */
24
final class JsonValidationException extends UnexpectedValueException
25
{
26
    private readonly ?string $validatedFile;
27
    private readonly array $errors;
28
29
    /**
30
     * @param string[] $errors
31
     */
32
    public function __construct(
33
        string $message,
34
        ?string $file = null,
35
        array $errors = [],
36
        int $code = 0,
37
        ?Throwable $previous = null,
38
    ) {
39
        if (null !== $file) {
40
            Assert::file($file);
41
        }
42
        Assert::allString($errors);
43
44
        $this->validatedFile = $file;
0 ignored issues
show
The property validatedFile is declared read-only in KevinGH\Box\Json\JsonValidationException.
Loading history...
45
        $this->errors = $errors;
0 ignored issues
show
The property errors is declared read-only in KevinGH\Box\Json\JsonValidationException.
Loading history...
46
47
        parent::__construct($message, $code, $previous);
48
    }
49
50
    public function getValidatedFile(): ?string
51
    {
52
        return $this->validatedFile;
53
    }
54
55
    /**
56
     * @return string[]
57
     */
58
    public function getErrors(): array
59
    {
60
        return $this->errors;
61
    }
62
}
63