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

ValidateHostIsPresent   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 16 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 ValidateHostIsPresent extends BaseURLValidator
12
{
13
    public function validate() : bool
14
    {
15
        // every link needs a host. This case can happen for ex, if
16
        // the link starts with a typo with only one slash, like:
17
        // "http:/hostname"
18
        if($this->hasHost() || $this->isSchemeLess()) {
19
            return true;
20
        }
21
22
        $this->parser->setError(
23
            URLInfo::ERROR_MISSING_HOST,
24
            t('Cannot determine the link\'s host name.') . ' ' .
25
            t('This usually happens when there\'s a typo somewhere.')
26
        );
27
28
        return false;
29
    }
30
}
31