Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
66.67% covered (warning)
66.67%
8 / 12
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
Uri
66.67% covered (warning)
66.67%
8 / 12
66.67% covered (warning)
66.67%
2 / 3
5.93
0.00% covered (danger)
0.00%
0 / 1
 createRandom
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 validate
60.00% covered (warning)
60.00%
6 / 10
0.00% covered (danger)
0.00%
0 / 1
3.58
 isAllowedUrl
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2namespace Apie\Core\ValueObjects;
3
4use Apie\Core\Attributes\Description;
5use Apie\Core\Attributes\ExampleValue;
6use Apie\Core\Attributes\FakeMethod;
7use Apie\Core\ValueObjects\Exceptions\InvalidStringForValueObjectException;
8use Apie\Core\ValueObjects\Interfaces\StringValueObjectInterface;
9use Faker\Generator;
10
11#[Description('URI in RFC 3986 format.')]
12#[FakeMethod('createRandom')]
13#[ExampleValue('https://apie-lib.blogspot.com/')]
14class Uri implements StringValueObjectInterface
15{
16    use IsStringValueObject;
17
18    public static function createRandom(Generator $faker): Uri
19    {
20        return new self($faker->url);
21    }
22
23    public static function validate(string $input): void
24    {
25        if (!filter_var($input, FILTER_VALIDATE_URL)) {
26            throw new InvalidStringForValueObjectException(
27                $input,
28                new \ReflectionClass(static::class)
29            );
30        }
31        if (!self::isAllowedUrl($input)) {
32            throw new InvalidStringForValueObjectException(
33                $input,
34                new \ReflectionClass(static::class)
35            );
36        }
37    }
38
39    protected static function isAllowedUrl(string $input): bool
40    {
41        return true;
42    }
43}