Passed
Push — master ( b083ab...a3db06 )
by Sebastian
03:30
created

ValidateSchemeIsSet   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 1
b 0
f 0
dl 0
loc 17
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 15 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AppUtils\URLInfo\Parser\URLValidator;
6
7
use AppUtils\URLInfo;
8
use AppUtils\URLInfo\Parser\BaseURLValidator;
9
use function AppUtils\t;
10
11
class ValidateSchemeIsSet extends BaseURLValidator
12
{
13
    public function validate() : bool
14
    {
15
        if($this->hasScheme() || $this->isFragmentOnly()) {
16
            return true;
17
        }
18
19
        // no scheme found: it may be an email address without the mailto:
20
        // It can't be a variable, since without the scheme it would already
21
        // have been recognized as a variable only link.
22
        $this->parser->setError(
23
            URLInfo::ERROR_MISSING_SCHEME,
24
            t('Cannot determine the link\'s scheme, e.g. %1$s.', 'http')
25
        );
26
27
        return false;
28
    }
29
}
30