Passed
Push — master ( f0d4c7...67a964 )
by Konrad
04:54
created

BlankNode::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 12
rs 10
ccs 6
cts 6
cp 1
crap 3
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 rdfInterface\BlankNode as iBlankNode;
16
use rdfInterface\Term;
17
18
class BlankNode implements iBlankNode
19
{
20
    private string $id;
21
22 4
    public function __construct(?string $id = null)
23
    {
24 4
        if (empty($id)) {
25
            // if no ID was given, generate random unique string
26 1
            $id = bin2hex(random_bytes(16));
27
        }
28
29 4
        if (!str_starts_with($id, '_:')) {
30 3
            $id = '_:'.$id;
31
        }
32
33 4
        $this->id = $id;
34 4
    }
35
36 1
    public function __toString(): string
37
    {
38 1
        return $this->id;
39
    }
40
41 1
    public function equals(Term $term): bool
42
    {
43 1
        return $this == $term;
44
    }
45
46 1
    public function getType(): string
47
    {
48 1
        return \rdfInterface\TYPE_BLANK_NODE;
49
    }
50
51 2
    public function getValue(): string
52
    {
53 2
        return $this->id;
54
    }
55
}
56