Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
75.00% |
3 / 4 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| BlankNode | |
75.00% |
3 / 4 |
|
66.67% |
2 / 3 |
5.39 | |
0.00% |
0 / 1 |
| __construct | |
50.00% |
1 / 2 |
|
0.00% |
0 / 1 |
2.50 | |||
| toNTriples | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| equals | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace LambdaTwelve\OneRecord\Rdf; |
| 6 | |
| 7 | use InvalidArgumentException; |
| 8 | |
| 9 | /** |
| 10 | * A node without a global identifier. Labels are only meaningful inside one |
| 11 | * graph; two graphs are compared modulo a relabelling of their blank nodes. |
| 12 | */ |
| 13 | final readonly class BlankNode implements Term |
| 14 | { |
| 15 | public function __construct(public string $label) |
| 16 | { |
| 17 | if (preg_match('/^[A-Za-z0-9_][A-Za-z0-9_.-]*$/', $label) !== 1) { |
| 18 | throw new InvalidArgumentException(\sprintf('Not a valid blank node label: "%s".', $label)); |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | public function toNTriples(): string |
| 23 | { |
| 24 | return '_:' . $this->label; |
| 25 | } |
| 26 | |
| 27 | public function equals(Term $other): bool |
| 28 | { |
| 29 | return $other instanceof self && $other->label === $this->label; |
| 30 | } |
| 31 | } |