Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
ExpandedDocument
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
3 / 3
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 rootIri
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 rootTypes
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace LambdaTwelve\OneRecord\JsonLd;
6
7use LambdaTwelve\OneRecord\Rdf\BlankNode;
8use LambdaTwelve\OneRecord\Rdf\Graph;
9use LambdaTwelve\OneRecord\Rdf\Iri;
10
11/**
12 * A JSON-LD document reduced to its RDF graph plus the two things the graph
13 * alone cannot tell: which node the document was about, and which context it
14 * used (kept so a response can be written back in the partner's own terms).
15 */
16final readonly class ExpandedDocument
17{
18    public function __construct(
19        public Graph $graph,
20        public Iri|BlankNode $root,
21        public Context $context,
22    ) {}
23
24    public function rootIri(): ?Iri
25    {
26        return $this->root instanceof Iri ? $this->root : null;
27    }
28
29    /**
30     * @return list<string> rdf:type IRIs of the root node, sorted
31     */
32    public function rootTypes(): array
33    {
34        $types = array_map(static fn(Iri $type): string => $type->value, $this->graph->typesOf($this->root));
35        sort($types, SORT_STRING);
36
37        return $types;
38    }
39}