LinkedDataResource   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 15
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

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