Passed
Push — extract-store ( 38a23e...9fc033 )
by Konrad
05:01
created

Literal::withLang()   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 Exception;
16
use rdfInterface\Literal as iLiteral;
17
use rdfInterface\Term;
18
use rdfInterface\TYPE_LITERAL;
0 ignored issues
show
Bug introduced by
The type rdfInterface\TYPE_LITERAL 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...
19
use Stringable;
20
use sweetrdf\InMemoryStoreSqlite\NamespaceHelper;
21
22
class Literal implements iLiteral
23
{
24
    private int | float | string | bool | Stringable $value;
25
26
    private ?string $lang;
27
28
    private ?string $datatype;
29
30 2
    public function __construct(
31
        int | float | string | bool | Stringable $value,
32
        ?string $lang = null,
33
        ?string $datatype = null
34
    ) {
35 2
        $this->value = $value;
36 2
        $this->lang = $lang;
37 2
        $this->datatype = $datatype;
38 2
    }
39
40
    public function __toString(): string
41
    {
42
        $langtype = '';
43
        if (!empty($this->lang)) {
44
            $langtype = '@'.$this->lang;
45
        } elseif (!empty($this->datatype)) {
46
            $langtype = "^^<$this->datatype>";
47
        }
48
49
        return '"'.$this->value.'"'.$langtype;
50
    }
51
52
    public function getValue(): int | float | string | bool | Stringable
53
    {
54
        return $this->value;
55
    }
56
57
    public function getLang(): ?string
58
    {
59
        return $this->lang;
60
    }
61
62
    public function getDatatype(): string
63
    {
64
        return $this->datatype ?? NamespaceHelper::NAMESPACE_XSD;
65
    }
66
67
    public function getType(): string
68
    {
69
        return TYPE_LITERAL;
70
    }
71
72
    public function equals(Term $term): bool
73
    {
74
        return $this === $term;
75
    }
76
77
    public function withValue(int | float | string | bool | Stringable $value): self
78
    {
79
        throw new Exception('withValue not implemented yet');
80
    }
81
82
    public function withLang(?string $lang): self
83
    {
84
        throw new Exception('withLang not implemented yet');
85
    }
86
87
    public function withDatatype(?string $datatype): self
88
    {
89
        throw new Exception('withDatatype not implemented yet');
90
    }
91
}
92