Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
InMemoryAccessDelegationStore
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
4 / 4
6
100.00% covered (success)
100.00%
1 / 1
 grant
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 grantsFor
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 eraseFor
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 revokeFrom
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace LambdaTwelve\OneRecord\Server\InMemory;
6
7use LambdaTwelve\OneRecord\Rdf\Iri;
8use LambdaTwelve\OneRecord\Server\Spi\AccessDelegationStore;
9use LambdaTwelve\OneRecord\Server\Spi\Grant;
10use LambdaTwelve\OneRecord\Server\Spi\Volatile;
11
12final class InMemoryAccessDelegationStore implements AccessDelegationStore, Volatile
13{
14    /** @var list<Grant> */
15    private array $grants = [];
16
17    public function grant(Grant $grant): void
18    {
19        $this->grants[] = $grant;
20    }
21
22    public function grantsFor(Iri $agent, Iri $logisticsObject): array
23    {
24        return array_values(array_filter($this->grants, static fn(Grant $g): bool => $g->agent->equals($agent) && $g->logisticsObject->equals($logisticsObject)));
25    }
26
27    public function eraseFor(Iri $logisticsObject): void
28    {
29        $this->grants = array_values(array_filter($this->grants, static fn(Grant $g): bool => !$g->logisticsObject->equals($logisticsObject)));
30    }
31
32    public function revokeFrom(Iri $accessDelegationRequest): void
33    {
34        $this->grants = array_values(array_filter($this->grants, static fn(Grant $g): bool => $g->source === null || !$g->source->equals($accessDelegationRequest)));
35    }
36}