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\FakeMethod;
6use Apie\Core\ValueObjects\Exceptions\InvalidStringForValueObjectException;
7use Apie\Core\ValueObjects\Interfaces\StringValueObjectInterface;
8use Faker\Generator;
9
10#[Description('URI in RFC 3986 format.')]
11#[FakeMethod('createRandom')]
12class Uri implements StringValueObjectInterface
13{
14    use IsStringValueObject;
15
16    public static function createRandom(Generator $faker): Uri
17    {
18        return new self($faker->url);
19    }
20
21    public static function validate(string $input): void
22    {
23        if (!filter_var($input, FILTER_VALIDATE_URL)) {
24            throw new InvalidStringForValueObjectException(
25                $input,
26                new \ReflectionClass(static::class)
27            );
28        }
29        if (!self::isAllowedUrl($input)) {
30            throw new InvalidStringForValueObjectException(
31                $input,
32                new \ReflectionClass(static::class)
33            );
34        }
35    }
36
37    protected static function isAllowedUrl(string $input): bool
38    {
39        return true;
40    }
41}