UrlType   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 4 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ecodev\Felix\Api\Scalar;
6
7
final class UrlType extends AbstractStringBasedType
8
{
9
    public ?string $description = 'An absolute web URL that must start with `http` or `https` or be an empty string.';
10
11
    /**
12
     * Validate an URL.
13
     */
14 46
    protected function isValid(?string $value): bool
15
    {
16
        // Here we use a naive pattern that should ideally be kept in sync with Natural validator
17 46
        return $value === '' || is_string($value) && preg_match('~^https?://(?:[^.\s]+\.)+[^.\s]+$~', $value);
18
    }
19
}
20