Passed
Push — master ( 4633d8...be0c82 )
by Alain
02:10
created

Domain::getDomain()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * BrightNucleus Chainmail Component.
4
 *
5
 * @package   BrightNucleus/Chainmail
6
 * @author    Alain Schlesser <[email protected]>
7
 * @license   MIT
8
 * @link      http://www.brightnucleus.com/
9
 * @copyright 2016 Alain Schlesser, Bright Nucleus
10
 */
11
12
namespace BrightNucleus\ChainMail\Support;
13
14
use BrightNucleus\Chainmail\Exception\InvalidDomain;
15
16
/**
17
 * Class Domain.
18
 *
19
 * @since   1.0.0
20
 *
21
 * @package BrightNucleus\ChainMail
22
 * @author  Alain Schlesser <[email protected]>
23
 */
24
class Domain
25
{
26
27
    /**
28
     * Domain name.
29
     *
30
     * @var string
31
     */
32
    protected $domain;
33
34
    /**
35
     * Instantiate a Domain object.
36
     *
37
     * @param Domain|string $domain
38
     *
39
     * @throws InvalidDomain If the domain is not valid.
40
     */
41
    public function __construct($domain)
42
    {
43
        if ( ! $this->isValid($domain)) {
44
            throw InvalidDomain::from($domain);
0 ignored issues
show
Bug introduced by
It seems like $domain defined by parameter $domain on line 41 can also be of type object<BrightNucleus\ChainMail\Support\Domain>; however, BrightNucleus\Chainmail\...n\InvalidDomain::from() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
45
        }
46
47
        $this->domain = (string)$domain;
48
    }
49
50
    /**
51
     * Return the domain name.
52
     *
53
     * @return string
54
     */
55
    public function getDomain()
56
    {
57
        return $this->domain;
58
    }
59
60
    /**
61
     * Reutrn a string representation of the Domain object.
62
     *
63
     * @return string
64
     */
65
    public function __toString()
66
    {
67
        return $this->getDomain();
68
    }
69
70
    /**
71
     * @param $domain
72
     *
73
     * @return bool
74
     */
75
    protected function isValid($domain)
76
    {
77
        // TODO: Implement real validation.
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
78
        return $domain === trim($domain);
79
    }
80
}