| Conditions | 2 |
| Paths | 9 |
| Total Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | public function resolve(int $timeout) : ?EasyRdf\Resource { |
||
| 9 | $client = new EasyRdf\Sparql\Client(self::WDQS_ENDPOINT); |
||
| 10 | try { |
||
| 11 | // unregister the legacy "json" format as it causes problems with CONSTRUCT requests |
||
| 12 | EasyRdf\Format::unregister('json'); |
||
| 13 | // change the timeout setting for external requests |
||
| 14 | $httpclient = EasyRdf\Http::getDefaultHttpClient(); |
||
| 15 | $httpclient->setConfig(array('timeout' => $timeout)); |
||
| 16 | $httpclient->setHeaders('Accept', 'text/turtle'); |
||
| 17 | EasyRdf\Http::setDefaultHttpClient($httpclient); |
||
| 18 | |||
| 19 | $uri = $this->uri; |
||
| 20 | $query = <<<EOQ |
||
| 21 | PREFIX wd: <http://www.wikidata.org/entity/> |
||
| 22 | PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> |
||
| 23 | PREFIX schema: <http://schema.org/> |
||
| 24 | |||
| 25 | CONSTRUCT { |
||
| 26 | <$uri> rdfs:label ?label . |
||
| 27 | ?link schema:about <$uri> . |
||
| 28 | } |
||
| 29 | WHERE |
||
| 30 | { |
||
| 31 | { <$uri> rdfs:label ?label } |
||
| 32 | UNION |
||
| 33 | { ?link schema:about <$uri> } |
||
| 34 | } |
||
| 35 | EOQ; |
||
| 36 | |||
| 37 | $client = new EasyRdf\Sparql\Client(self::WDQS_ENDPOINT); |
||
| 38 | $graph = $client->query($query); |
||
| 39 | return $graph->resource($this->uri); |
||
|
|
|||
| 40 | } catch (Exception $e) { |
||
| 41 | $this->model->getLogger()->info("WDQS resolution failed for <{$this->uri}>: $e"); |
||
| 42 | return null; |
||
| 43 | } |
||
| 44 | } |
||
| 45 | } |
||
| 46 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: