DNSName::name()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
nc 1
cc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace X509\GeneralName;
6
7
use ASN1\Type\TaggedType;
8
use ASN1\Type\UnspecifiedType;
9
use ASN1\Type\Primitive\IA5String;
10
use ASN1\Type\Tagged\ImplicitlyTaggedType;
11
12
/**
13
 * Implements <i>dNSName</i> CHOICE type of <i>GeneralName</i>.
14
 *
15
 * @link https://tools.ietf.org/html/rfc5280#section-4.2.1.6
16
 */
17
class DNSName extends GeneralName
18
{
19
    /**
20
     * DNS name.
21
     *
22
     * @var string
23
     */
24
    protected $_name;
25
    
26
    /**
27
     * Constructor.
28
     *
29
     * @param string $name Domain name
30
     */
31 26
    public function __construct(string $name)
32
    {
33 26
        $this->_tag = self::TAG_DNS_NAME;
34 26
        $this->_name = $name;
35 26
    }
36
    
37
    /**
38
     *
39
     * @param UnspecifiedType $el
40
     * @return self
41
     */
42 13
    public static function fromChosenASN1(UnspecifiedType $el): self
43
    {
44 13
        return new self($el->asIA5String()->string());
45
    }
46
    
47
    /**
48
     *
49
     * {@inheritdoc}
50
     */
51 3
    public function string(): string
52
    {
53 3
        return $this->_name;
54
    }
55
    
56
    /**
57
     * Get DNS name.
58
     *
59
     * @return string
60
     */
61 4
    public function name(): string
62
    {
63 4
        return $this->_name;
64
    }
65
    
66
    /**
67
     *
68
     * {@inheritdoc}
69
     */
70 24
    protected function _choiceASN1(): TaggedType
71
    {
72 24
        return new ImplicitlyTaggedType($this->_tag, new IA5String($this->_name));
73
    }
74
}
75