Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
JsonLdException
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
3 / 3
4
100.00% covered (success)
100.00%
1 / 1
 at
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 unsupported
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 invalidJson
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace LambdaTwelve\OneRecord\JsonLd;
6
7use RuntimeException;
8
9/**
10 * A document is outside the JSON-LD subset ONE Record uses, or malformed.
11 *
12 * The subset is deliberate (see docs/guide/json-ld.md): anything this package
13 * cannot represent faithfully is refused with a message naming the construct
14 * and where it was found, instead of being silently misread.
15 */
16final class JsonLdException extends RuntimeException
17{
18    public static function at(string $path, string $message): self
19    {
20        return new self(\sprintf('%s at %s', $message, $path === '' ? 'the document root' : $path));
21    }
22
23    public static function unsupported(string $path, string $keyword): self
24    {
25        return self::at($path, \sprintf('%s is outside the JSON-LD subset this package supports', $keyword));
26    }
27
28    public static function invalidJson(string $reason): self
29    {
30        return new self('The document is not valid JSON: ' . $reason);
31    }
32}