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

ValidateSchemeIsKnown   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 9
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 AppUtils\URLInfo\URISchemes;
10
use function AppUtils\t;
11
12
class ValidateSchemeIsKnown extends BaseURLValidator
13
{
14
    public function validate() : bool
15
    {
16
        if(!$this->hasScheme() || URISchemes::isValidSchemeName((string)$this->getScheme())) {
17
            return true;
18
        }
19
20
        $this->setScheme('');
21
22
        $this->parser->setError(
23
            URLInfo::ERROR_INVALID_SCHEME,
24
            t('The scheme %1$s is not supported for links.', $this->getScheme()) . ' ' .
25
            t('Valid schemes are: %1$s.', implode(', ', URISchemes::getSchemeNames()))
26
        );
27
28
        return false;
29
    }
30
}
31