Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
4 / 4 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| Operation | |
100.00% |
4 / 4 |
|
100.00% |
4 / 4 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| add | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| delete | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| subjectString | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace LambdaTwelve\OneRecord\Change; |
| 6 | |
| 7 | use LambdaTwelve\OneRecord\Rdf\BlankNode; |
| 8 | use LambdaTwelve\OneRecord\Rdf\Iri; |
| 9 | |
| 10 | /** |
| 11 | * api:Operation: add or delete one triple. The subject is the logistics |
| 12 | * object, one of its embedded objects, or a blank node this change adds. |
| 13 | */ |
| 14 | final readonly class Operation |
| 15 | { |
| 16 | public function __construct( |
| 17 | public OperationKind $kind, |
| 18 | public Iri|BlankNode $subject, |
| 19 | public Iri $predicate, |
| 20 | public OperationObject $object, |
| 21 | ) {} |
| 22 | |
| 23 | public static function add(Iri|BlankNode $subject, Iri $predicate, OperationObject $object): self |
| 24 | { |
| 25 | return new self(OperationKind::Add, $subject, $predicate, $object); |
| 26 | } |
| 27 | |
| 28 | public static function delete(Iri|BlankNode $subject, Iri $predicate, OperationObject $object): self |
| 29 | { |
| 30 | return new self(OperationKind::Delete, $subject, $predicate, $object); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * The subject as it appears in api:s: an IRI, or a `_:label` string. |
| 35 | */ |
| 36 | public function subjectString(): string |
| 37 | { |
| 38 | return $this->subject instanceof Iri ? $this->subject->value : $this->subject->toNTriples(); |
| 39 | } |
| 40 | } |