Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
80.00% |
4 / 5 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
| ResolvedGraph | |
80.00% |
4 / 5 |
|
75.00% |
3 / 4 |
5.20 | |
0.00% |
0 / 1 |
| __construct | |
50.00% |
1 / 2 |
|
0.00% |
0 / 1 |
2.50 | |||
| root | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| iris | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace LambdaTwelve\OneRecord\Model; |
| 6 | |
| 7 | use LambdaTwelve\OneRecord\Rdf\Iri; |
| 8 | |
| 9 | /** |
| 10 | * A local graph after URIs were minted: the objects to publish, keyed by the |
| 11 | * local key the host knows them by, so it can record where each one went. |
| 12 | */ |
| 13 | final readonly class ResolvedGraph |
| 14 | { |
| 15 | /** |
| 16 | * @param array<string, LogisticsObject> $objects local key => object |
| 17 | */ |
| 18 | public function __construct( |
| 19 | public string $rootKey, |
| 20 | public array $objects, |
| 21 | ) { |
| 22 | if (!isset($objects[$rootKey])) { |
| 23 | throw new ModelException(\sprintf('The resolved graph has no object for its root key "%s".', $rootKey)); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | public function root(): LogisticsObject |
| 28 | { |
| 29 | return $this->objects[$this->rootKey]; |
| 30 | } |
| 31 | |
| 32 | public function get(string $key): LogisticsObject |
| 33 | { |
| 34 | return $this->objects[$key] ?? throw new ModelException(\sprintf('No object with key "%s".', $key)); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * @return array<string, Iri> local key => URI |
| 39 | */ |
| 40 | public function iris(): array |
| 41 | { |
| 42 | return array_map(static fn(LogisticsObject $o): Iri => $o->iri, $this->objects); |
| 43 | } |
| 44 | } |