JsonSchemaScopeResolver   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 37
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B resolve() 0 15 5
1
<?php
2
3
namespace League\JsonReference\ScopeResolver;
4
5
use League\JsonReference\ScopeResolverInterface;
6
use function League\JsonReference\resolve_uri;
7
8
final class JsonSchemaScopeResolver implements ScopeResolverInterface
9
{
10
    const KEYWORD_DRAFT_4 = 'id';
11
    const KEYWORD_DRAFT_6 = '$id';
12
13
    /**
14
     * @var string
15
     */
16
    private $keyword;
17
18
    /**
19
     * @param string $keyword
20
     */
21 2
    public function __construct($keyword)
22
    {
23 2
        $this->keyword = $keyword;
24 2
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 2
    public function resolve($schema, $currentPointer, $currentScope)
30
    {
31 2
        $current = $schema;
32 2
        foreach (explode('/', $currentPointer) as $segment) {
33 2
            if (isset($current->$segment)) {
34 2
                $current = $current->$segment;
35 1
            }
36 2
            $id = isset($current->{$this->keyword}) ? $current->{$this->keyword} : null;
37 2
            if (is_string($id)) {
38 2
                $currentScope = resolve_uri($id, $currentScope);
39 1
            }
40 1
        }
41
42 2
        return $currentScope;
43
    }
44
}
45