Passed
Pull Request — master (#26)
by Viacheslav
03:12
created

InvalidValue::inspect()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 10
cts 10
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 2
nop 1
crap 3
1
<?php
2
3
namespace Swaggest\JsonSchema;
4
5
use Swaggest\JsonSchema\Exception\Error;
6
use Swaggest\JsonSchema\Exception\LogicException;
7
use Swaggest\JsonSchema\Path\PointerUtil;
8
9
class InvalidValue extends Exception
10
{
11
    public $error;
12
    public $path;
13
14 754
    public function addPath($path)
15
    {
16 754
        if ($this->error === null) {
17 754
            $this->error = $this->message;
18
        }
19 754
        $this->path = $path;
20 754
        $this->message .= ' at ' . $path;
21 754
    }
22
23
    const INVALID_VALUE = 1;
24
    const NOT_IMPLEMENTED = 2;
25
26
27 1
    public static function inspect(InvalidValue $invalidValue)
28
    {
29 1
        $error = new Error();
30 1
        $error->error = $invalidValue->error;
31 1
        $error->processingPath = $invalidValue->path;
32 1
        $error->dataPointer = PointerUtil::getDataPointer($error->processingPath);
33 1
        $error->schemaPointers = PointerUtil::getSchemaPointers($error->processingPath);
34 1
        if ($invalidValue instanceof LogicException) {
35 1
            foreach ($invalidValue->subErrors as $nestedError) {
36 1
                $error->subErrors[] = self::inspect($nestedError);
37
            }
38
        }
39 1
        return $error;
40
    }
41
}