Passed
Branch extract-store (f24e42)
by Konrad
04:37
created

Quad::withObject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace sweetrdf\InMemoryStoreSqlite\Rdf;
4
5
/*
6
 * This file is part of the sweetrdf/InMemoryStoreSqlite package and licensed under
7
 * the terms of the GPL-3 license.
8
 *
9
 * (c) Konrad Abicht <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
use BadMethodCallException;
16
use Exception;
17
use rdfInterface\BlankNode as iBlankNode;
18
use rdfInterface\Literal as iLiteral;
19
use rdfInterface\NamedNode as iNamedNode;
20
use rdfInterface\Quad as iQuad;
21
use rdfInterface\Term as iTerm;
22
23
class Quad implements iQuad
24
{
25
    private iTerm $subject;
26
27
    private iNamedNode $predicate;
28
29
    private iTerm $object;
30
31
    private iNamedNode | iBlankNode | null $graphIri;
0 ignored issues
show
Bug introduced by
The type sweetrdf\InMemoryStoreSqlite\Rdf\null was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
32
33
    public function __construct(
34
        iTerm $subject,
35
        iNamedNode $predicate,
36
        iTerm $object,
37
        iNamedNode | iBlankNode | null $graphIri = null
38
    ) {
39
        if ($subject instanceof iLiteral) {
40
            throw new BadMethodCallException('Subject must be of type NamedNode or BlankNode');
41
        }
42
        $this->subject = $subject;
43
        $this->predicate = $predicate;
44
        $this->object = $object;
45
        $this->graphIri = $graphIri ?? new DefaultGraph();
46
    }
47
48
    public function __toString(): string
49
    {
50
        return rtrim("$this->subject $this->predicate $this->object $this->graphIri");
51
    }
52
53
    public function getType(): string
54
    {
55
        return \rdfInterface\TYPE_QUAD;
56
    }
57
58
    public function equals(iTerm $term): bool
59
    {
60
        return $this === $term;
61
    }
62
63
    public function getValue(): string
64
    {
65
        throw new BadMethodCallException();
66
    }
67
68
    public function getSubject(): iTerm
69
    {
70
        return $this->subject;
71
    }
72
73
    public function getPredicate(): iNamedNode
74
    {
75
        return $this->predicate;
76
    }
77
78
    public function getObject(): iTerm
79
    {
80
        return $this->object;
81
    }
82
83
    public function getGraphIri(): iNamedNode | iBlankNode
84
    {
85
        return $this->graphIri;
86
    }
87
88
    public static function createFromArray(array $triple, string $graph): iQuad
89
    {
90
        /*
91
         * subject
92
         */
93
        if ('uri' == $triple['s_type']) {
94
            $s = new NamedNode($triple['s']);
95
        } elseif ('bnode' == $triple['s_type']) {
96
            $s = new BlankNode($triple['s']);
97
        } else {
98
            throw new Exception('Invalid subject type given.');
99
        }
100
101
        // predicate
102
        $p = new NamedNode($triple['p']);
103
104
        /*
105
         * object
106
         */
107
        if ('uri' == $triple['o_type']) {
108
            $o = new NamedNode($triple['o']);
109
        } elseif ('bnode' == $triple['o_type']) {
110
            $o = new BlankNode($triple['o']);
111
        } elseif ('literal' == $triple['o_type']) {
112
            $o = new Literal($triple['o'], $triple['o_lang'], $triple['o_datatype']);
113
        } else {
114
            throw new Exception('Invalid object type given.');
115
        }
116
117
        $g = !empty($graph) ? new NamedNode($graph) : new DefaultGraph();
118
119
        return new self($s, $p, $o, $g);
120
    }
121
122
    public function withSubject(iTerm $subject): iQuad
123
    {
124
        throw new Exception('withSubject not implemented yet.');
125
    }
126
127
    public function withPredicate(iNamedNode $predicate): iQuad
128
    {
129
        throw new Exception('withPredicate not implemented yet.');
130
    }
131
132
    public function withObject(iTerm $object): iQuad
133
    {
134
        throw new Exception('withObject not implemented yet.');
135
    }
136
137
    public function withGraphIri(iNamedNode | iBlankNode $graphIri): iQuad
138
    {
139
        throw new Exception('withGraphIri not implemented yet.');
140
    }
141
}
142