Resolver   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 11
dl 0
loc 33
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A startsWith() 0 3 1
A resolve() 0 10 3
1
<?php
2
3
class Resolver
4
{
5
    private $model;
6
7
    /**
8
     * Initializes the Resolver object
9
     */
10
    public function __construct($model)
11
    {
12
        $this->model = $model;
13
    }
14
15
    private function startsWith(string $prefix, string $target): bool
16
    {
17
        return strpos($target, $prefix) === 0;
18
    }
19
20
    /**
21
     * Resolve the URI using the most appropriate resolver and return the
22
     * result as an ExternalResource.
23
     * @param string $uri URI to resolve
24
     * @return EasyRdf\Resource
25
     */
26
    public function resolve(string $uri, int $timeout): ?EasyRdf\Resource
27
    {
28
        if (preg_match('|http://id.loc.gov/[^/]+/[^/]+/.+|', $uri)) {
29
            $res = new LOCResource($this->model, $uri);
30
        } elseif ($this->startsWith('http://www.wikidata.org/entity/', $uri)) {
31
            $res = new WDQSResource($this->model, $uri);
32
        } else {
33
            $res = new LinkedDataResource($this->model, $uri);
34
        }
35
        return $res->resolve($timeout);
36
    }
37
}
38