TargetName::fromChosenASN1()   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 1
crap 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace X509\Certificate\Extension\Target;
6
7
use ASN1\Type\TaggedType;
8
use ASN1\Type\Tagged\ExplicitlyTaggedType;
9
use X509\GeneralName\GeneralName;
10
11
/**
12
 * Implements 'targetName' CHOICE of the <i>Target</i> ASN.1 type.
13
 *
14
 * @link https://tools.ietf.org/html/rfc5755#section-4.3.2
15
 */
16
class TargetName extends Target
17
{
18
    /**
19
     * Name.
20
     *
21
     * @var GeneralName $_name
22
     */
23
    protected $_name;
24
    
25
    /**
26
     * Constructor.
27
     *
28
     * @param GeneralName $name
29
     */
30 16
    public function __construct(GeneralName $name)
31
    {
32 16
        $this->_name = $name;
33 16
        $this->_type = self::TYPE_NAME;
34 16
    }
35
    
36
    /**
37
     *
38
     * @param TaggedType $el
39
     * @return self
40
     */
41 5
    public static function fromChosenASN1(TaggedType $el): self
42
    {
43 5
        return new self(GeneralName::fromASN1($el));
44
    }
45
    
46
    /**
47
     *
48
     * {@inheritdoc}
49
     */
50 3
    public function string(): string
51
    {
52 3
        return $this->_name->string();
53
    }
54
    
55
    /**
56
     * Get name.
57
     *
58
     * @return GeneralName
59
     */
60 1
    public function name(): GeneralName
61
    {
62 1
        return $this->_name;
63
    }
64
    
65
    /**
66
     *
67
     * {@inheritdoc}
68
     * @return ExplicitlyTaggedType
69
     */
70 13
    public function toASN1(): TaggedType
71
    {
72 13
        return new ExplicitlyTaggedType($this->_type, $this->_name->toASN1());
73
    }
74
}
75