IsUrl::check()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 15
rs 9.6111
cc 5
nc 4
nop 1
1
<?php
2
/**
3
 * @author    Nurlan Mukhanov <[email protected]>
4
 * @copyright 2022 Nurlan Mukhanov
5
 * @license   https://en.wikipedia.org/wiki/MIT_License MIT License
6
 * @link      https://github.com/Falseclock/service-layer
7
 */
8
9
declare(strict_types=1);
10
11
namespace Falseclock\Service\Validation\Validators;
12
13
class IsUrl extends IsString
14
{
15
    /**
16
     * @param $value
17
     * @return bool
18
     */
19
    public function check($value = null): bool
20
    {
21
        if (!parent::check($value)) {
22
            return false;
23
        }
24
25
        if (is_null($value) && $this->nullable) {
26
            return true;
27
        }
28
29
        if (!filter_var($value, FILTER_VALIDATE_URL)) {
30
            return false;
31
        }
32
33
        return true;
34
    }
35
}
36