Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
88.89% |
8 / 9 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| Deprecations | |
88.89% |
8 / 9 |
|
0.00% |
0 / 1 |
4.02 | |
0.00% |
0 / 1 |
| log | |
88.89% |
8 / 9 |
|
0.00% |
0 / 1 |
4.02 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace LambdaTwelve\OneRecord\Server; |
| 6 | |
| 7 | use LambdaTwelve\OneRecord\Rdf\Graph; |
| 8 | use LambdaTwelve\OneRecord\Rdf\Iri; |
| 9 | use LambdaTwelve\OneRecord\Vocabulary\Vocabulary; |
| 10 | use Psr\Log\LoggerInterface; |
| 11 | |
| 12 | /** |
| 13 | * Deprecated terms are accepted, as the compatibility guide promises, and |
| 14 | * their use is logged so a host can see what to migrate before an edition |
| 15 | * removes them. |
| 16 | */ |
| 17 | final class Deprecations |
| 18 | { |
| 19 | public static function log(Graph $graph, Iri $about, Vocabulary $vocabulary, LoggerInterface $logger): void |
| 20 | { |
| 21 | $seen = []; |
| 22 | foreach ($graph as $triple) { |
| 23 | $predicate = $triple->predicate->value; |
| 24 | if (isset($seen[$predicate])) { |
| 25 | continue; |
| 26 | } |
| 27 | $seen[$predicate] = true; |
| 28 | $info = $vocabulary->property($predicate); |
| 29 | if ($info?->deprecatedIn !== null) { |
| 30 | $logger->notice(\sprintf('%s uses %s, deprecated in data model %s.', $about->value, $predicate, $info->deprecatedIn), ['object' => $about->value, 'property' => $predicate, 'deprecatedIn' => $info->deprecatedIn]); |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | } |