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

InvalidValue::getDataPointer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 1
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 function inspect()
28
    {
29 1
        $error = new Error();
30 1
        $error->error = $this->error;
31 1
        $error->processingPath = $this->path;
32 1
        $error->dataPointer = PointerUtil::getDataPointer($error->processingPath);
33 1
        $error->schemaPointers = PointerUtil::getSchemaPointers($error->processingPath);
34 1
        if ($this instanceof LogicException) {
35 1
            foreach ($this->subErrors as $subError) {
36 1
                $error->subErrors[] = $subError->inspect();
37
            }
38
        }
39 1
        return $error;
40
    }
41
42 1
    public function getSchemaPointer()
43
    {
44 1
        return PointerUtil::getSchemaPointer($this->path);
45
    }
46
47 1
    public function getDataPointer()
48
    {
49 1
        return PointerUtil::getDataPointer($this->path);
50
    }
51
52
}