Passed
Pull Request — master (#3)
by Joao
04:02
created

SparQLDataset   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 46.15%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 55
ccs 12
cts 26
cp 0.4615
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 4
A getCapabilities() 0 15 3
A getIterator() 0 5 1
1
<?php
2
3
namespace ByJG\AnyDataset\Dataset;
4
5
use SparQL\Connection;
6
7
class SparQLDataset
8
{
9
10
    /**
11
     * @var object
12
     */
13
    private $connection;
14
15
    /**
16
     *
17
     * @param string $url
18
     * @param string $namespaces
19
     */
20 4
    public function __construct($url, $namespaces = null)
21
    {
22 4
        $this->connection = new Connection($url);
23
24 4
        if (is_array($namespaces)) {
25 3
            foreach ($namespaces as $key => $value) {
26 3
                $this->connection->ns($key, $value);
27 3
            }
28 3
        }
29
30 4
        if (function_exists('dba_open')) {
31
            $cache = sys_get_temp_dir() . "/caps.db";
32
            $this->connection->capabilityCache($cache);
33
        }
34 4
    }
35
36
    public function getCapabilities()
37
    {
38
        $return = array();
39
40
        if (function_exists('dba_open')) {
41
            foreach ($this->connection->capabilityCodes() as $code) {
42
                $return[$code] = array(
43
                    $this->connection->supports($code),
44
                    $this->connection->capabilityDescription($code)
45
                );
46
            }
47
        }
48
49
        return $return;
50
    }
51
52
    /**
53
     * @param string $sparql
54
     * @return GenericIterator
55
     */
56 4
    public function getIterator($sparql)
57
    {
58 4
        $result = $this->connection->query($sparql);
59 2
        return new SparQLIterator($result);
60
    }
61
}
62