Resolver::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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