ValidationFailedException   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 35
ccs 12
cts 12
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A fromErrors() 0 7 1
A __construct() 0 6 1
A getErrors() 0 4 1
A getErrorsAsString() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Webmozart JSON package.
5
 *
6
 * (c) Bernhard Schussek <[email protected]>
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 Webmozart\Json;
13
14
/**
15
 * Thrown when a JSON file contains invalid JSON.
16
 *
17
 * @since  1.0
18
 *
19
 * @author Bernhard Schussek <[email protected]>
20
 */
21
class ValidationFailedException extends \Exception
22
{
23
    private $errors;
24
25 8
    public static function fromErrors(array $errors = array(), $code = 0, \Exception $previous = null)
26
    {
27 8
        return new static(sprintf(
28 8
            "Validation of the JSON data failed:\n%s",
29 8
            implode("\n", $errors)
30
        ), $errors, $code, $previous);
31
    }
32
33 8
    public function __construct($message = '', array $errors = array(), $code = 0, \Exception $previous = null)
34
    {
35 8
        $this->errors = $errors;
36
37 8
        parent::__construct($message, $code, $previous);
38 8
    }
39
40
    /**
41
     * @return array
42
     */
43 4
    public function getErrors()
44
    {
45 4
        return $this->errors;
46
    }
47
48
    /**
49
     * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
50
     */
51 4
    public function getErrorsAsString()
52
    {
53 4
        return implode("\n", $this->errors);
54
    }
55
}
56