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

ValidateSchemeIsKnown::validate()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 15
rs 10
cc 3
nc 2
nop 0
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