Url   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
eloc 5
c 3
b 0
f 0
dl 0
loc 18
ccs 6
cts 6
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 3 1
A applicableToTypes() 0 3 1
A getMessage() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace PrinsFrank\PhpStrictModels\Rule;
5
6
use Attribute;
7
use PrinsFrank\PhpStrictModels\Enum\Type;
8
9
#[Attribute]
10
class Url implements Rule
11
{
12
    /** @return Type[] */
13 1
    public function applicableToTypes(): array
14
    {
15 1
        return [Type::string];
16
    }
17
18
    /** @param string $value */
19 1
    public function isValid(mixed $value): bool
20
    {
21 1
        return filter_var($value, FILTER_VALIDATE_URL) !== false;
22
    }
23
24 1
    public function getMessage(): string
25
    {
26 1
        return 'Should be a valid URL';
27
    }
28
}
29