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

InvalidValue   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
dl 0
loc 41
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addPath() 0 7 2
A getSchemaPointer() 0 3 1
A getDataPointer() 0 3 1
A inspect() 0 13 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 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
}