Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| Diff | |
100.00% |
10 / 10 |
|
100.00% |
3 / 3 |
7 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isEqual | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| describe | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace LambdaTwelve\OneRecord\JsonLd; |
| 6 | |
| 7 | use LambdaTwelve\OneRecord\Rdf\Triple; |
| 8 | |
| 9 | /** |
| 10 | * The outcome of comparing two graphs: the triples (in canonical form) each |
| 11 | * side has that the other lacks. Empty on both sides means isomorphic. |
| 12 | */ |
| 13 | final readonly class Diff |
| 14 | { |
| 15 | /** |
| 16 | * @param list<Triple> $onlyInLeft |
| 17 | * @param list<Triple> $onlyInRight |
| 18 | */ |
| 19 | public function __construct( |
| 20 | public array $onlyInLeft, |
| 21 | public array $onlyInRight, |
| 22 | ) {} |
| 23 | |
| 24 | public function isEqual(): bool |
| 25 | { |
| 26 | return $this->onlyInLeft === [] && $this->onlyInRight === []; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * A readable report for test output and interop logs. |
| 31 | */ |
| 32 | public function describe(): string |
| 33 | { |
| 34 | if ($this->isEqual()) { |
| 35 | return 'The graphs are isomorphic.'; |
| 36 | } |
| 37 | $lines = []; |
| 38 | foreach ($this->onlyInLeft as $triple) { |
| 39 | $lines[] = '- ' . $triple->toNTriples(); |
| 40 | } |
| 41 | foreach ($this->onlyInRight as $triple) { |
| 42 | $lines[] = '+ ' . $triple->toNTriples(); |
| 43 | } |
| 44 | |
| 45 | return implode("\n", $lines); |
| 46 | } |
| 47 | } |