Domain::getDomain()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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 null|string
30
     */
31
    private $domain;
32
33
    /**
34
     * Return domain name.
35
     *
36
     * @return null|string
37
     */
38 472
    public function getDomain(): ?string
39
    {
40 472
        return $this->domain;
41
    }
42
43
    /**
44
     * Set domain name.
45
     *
46
     * @param null|string $domain
47
     *
48
     * @return static
49
     *
50
     * @throws \InvalidArgumentException
51
     */
52 146
    public function setDomain(?string $domain): self
53
    {
54 146
        $domain = Url::normalizeUrl((string) $domain);
55
56 146
        if (is_string($domain)) {
57 144
            $this->domain = rtrim($domain, '/');
58
        } else {
59 2
            throw new InvalidArgumentException('Domain name is not valid.');
60
        }
61
62 144
        return $this;
63
    }
64
}
65