Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ActiveUriScheme
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 getActiveData
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 validate
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2namespace Apie\IanaValueObjects\UriScheme;
3
4use Apie\Core\ValueObjects\Exceptions\InvalidStringForValueObjectException;
5use Apie\Core\ValueObjects\Interfaces\LimitedOptionsInterface;
6use Apie\Core\ValueObjects\Interfaces\StringValueObjectInterface;
7use Apie\IanaValueObjects\HasActiveFilter;
8
9/**
10 * All URI schemes registered in the IANA URI Schemes Registry.
11 *
12 * @see https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml
13 *
14 * Only active URI schemes can be used (e.g. Permanent or Provisional, not Historical).
15 */
16final class ActiveUriScheme implements StringValueObjectInterface, LimitedOptionsInterface
17{
18    use IsUriScheme {
19        validate as private validLanguage;
20    }
21    use HasActiveFilter;
22
23    protected static function getActiveData(): array
24    {
25        return array_filter(static::getData(), function (array $data) {
26            $status = $data['Status'] ?? null;
27            return in_array($status, ['Permanent', 'Provisional']);
28        });
29    }
30
31    public static function validate(string $input): void
32    {
33        $data = static::getData()[$input] ?? null;
34        $status = $data['Status'] ?? null;
35        if ($status !== 'Permanent' && $status !== 'Provisional') {
36            throw new InvalidStringForValueObjectException(
37                $input,
38                (new \ReflectionClass(static::class))
39            );
40        }
41
42        static::validLanguage($input);
43    }
44}