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

ValidateHostIsPresent::validate()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 16
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 16
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 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