Completed
Push — master ( 751599...c13dee )
by Osma
02:10 queued 10s
created

Resolver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 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
        return strpos($target, $prefix) === 0;
17
    }
18
19
    /**
20
     * Resolve the URI using the most appropriate resolver and return the
21
     * result as an ExternalResource.
22
     * @param string $uri URI to resolve
23
     * @return EasyRdf\Resource
24
     */
25
    public function resolve(string $uri, int $timeout): ?EasyRdf\Resource {
26
        if (preg_match('|http://id.loc.gov/[^/]+/[^/]+/.+|', $uri)) {
27
            $res = new LOCResource($this->model, $uri);
28
        } elseif ($this->startsWith('http://www.wikidata.org/entity/', $uri)) {
29
            $res = new WDQSResource($this->model, $uri);
30
        } else {
31
            $res = new LinkedDataResource($this->model, $uri);
32
        }
33
        return $res->resolve($timeout);
34
    }
35
}
36