Completed
Push — master ( a2888f...6d16ff )
by Joao
04:13
created

SparQLDataset::__construct()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4.25

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 15
ccs 9
cts 12
cp 0.75
rs 9.2
cc 4
eloc 8
nc 4
nop 2
crap 4.25
1
<?php
2
3
namespace ByJG\AnyDataset\Repository;
4
5
use SparQL\Connection;
6
7
class SparQLDataset
8
{
9
10
    /**
11
     * @var object
12
     */
13
    private $_db;
14
15
    /**
16
     *
17
     * @param string $url
18
     * @param string $namespaces
19
     */
20 5
    public function __construct($url, $namespaces = null)
21
    {
22 5
        $this->_db = new Connection($url);
23
24 5
        if (is_array($namespaces)) {
25 3
            foreach ($namespaces as $key => $value) {
26 3
                $this->_db->ns($key, $value);
27 3
            }
28 3
        }
29
30 5
        if (function_exists('dba_open')) {
31
            $cache = sys_get_temp_dir() . "/caps.db";
32
            $this->_db->capabilityCache($cache);
33
        }
34 5
    }
35
36 1
    public function getCapabilities()
37
    {
38 1
        $return = array();
39
40 1
        if (function_exists('dba_open')) {
41
            foreach ($this->_db->capabilityCodes() as $code) {
42
                $return[$code] = array($this->_db->supports($code), $this->_db->capabilityDescription($code));
43
            }
44
        }
45
46 1
        return $return;
47
    }
48
49
    /**
50
     * @param string $sparql
51
     * @return DBIterator
52
     */
53 4
    public function getIterator($sparql)
54
    {
55 4
        $result = $this->_db->query($sparql);
56 2
        return new SparQLIterator($result);
57
    }
58
}
59