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

LinkedDataResource   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 7

1 Method

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 24 2
1
<?php
2
3
class LinkedDataResource extends RemoteResource
4
{
5
    public function resolve(int $timeout) : ?EasyRdf\Resource {
6
        // prevent parsing errors for sources which return invalid JSON (see #447)
7
        // 1. Unregister the legacy RDF/JSON parser, we don't want to use it
8
        EasyRdf\Format::unregister('json');
9
        // 2. Add "application/json" as a possible MIME type for the JSON-LD format
10
        $jsonld = EasyRdf\Format::getFormat('jsonld');
11
        $mimetypes = $jsonld->getMimeTypes();
12
        $mimetypes['application/json'] = 0.5;
13
        $jsonld->setMimeTypes($mimetypes);
14
15
        try {
16
            // change the timeout setting for external requests
17
            $httpclient = EasyRdf\Http::getDefaultHttpClient();
18
            $httpclient->setConfig(array('timeout' => $timeout));
19
            EasyRdf\Http::setDefaultHttpClient($httpclient);
20
21
            $graph = EasyRdf\Graph::newAndLoad(EasyRdf\Utils::removeFragmentFromUri($this->uri));
22
            return $graph->resource($this->uri);
23
        } catch (Exception $e) {
24
            $this->model->getLogger()->info("LD resolution failed for <{$this->uri}>: $e");
25
            return null;
26
        }
27
    
28
    }
29
30
}
31