Completed
Push — master ( 7fe6b0...d8a5ea )
by Paweł
02:19
created

Domain::setDomain()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Wszetko Sitemap.
7
 *
8
 * (c) Paweł Kłopotek-Główczewski <[email protected]>
9
 *
10
 * This source file is subject to the MIT license that is bundled
11
 * with this source code in the file LICENSE.
12
 */
13
14
namespace Wszetko\Sitemap\Traits;
15
16
use InvalidArgumentException;
17
use Wszetko\Sitemap\Helpers\Url;
18
19
/**
20
 * Trait Domain.
21
 *
22
 * @package Wszetko\Sitemap\Traits
23
 */
24
trait Domain
25
{
26
    /**
27
     * Domain.
28
     *
29
     * @var string
30
     */
31
    private $domain;
32
33
    /**
34
     * @return null|string
35
     */
36 462
    public function getDomain(): ?string
37
    {
38 462
        return $this->domain;
39
    }
40
41
    /**
42
     * @param null|string $domain
43
     *
44
     * @return self
45
     */
46 130
    public function setDomain(?string $domain): self
47
    {
48 130
        if ($domain = Url::normalizeUrl((string) $domain)) {
49 128
            $this->domain = rtrim($domain, '/');
50
        } else {
51 2
            throw new InvalidArgumentException('Domain name is not valid.');
52
        }
53
54 128
        return $this;
55
    }
56
}
57