DirectoryName   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 71
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A fromChosenASN1() 0 4 1
A fromDNString() 0 4 1
A string() 0 4 1
A dn() 0 4 1
A _choiceASN1() 0 6 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\Tagged\ExplicitlyTaggedType;
10
use X501\ASN1\Name;
11
12
/**
13
 * Implements <i>directoryName</i> CHOICE type of <i>GeneralName</i>.
14
 *
15
 * @link https://tools.ietf.org/html/rfc5280#section-4.2.1.6
16
 */
17
class DirectoryName extends GeneralName
18
{
19
    /**
20
     * Directory name.
21
     *
22
     * @var Name $_dn
23
     */
24
    protected $_dn;
25
    
26
    /**
27
     * Constructor.
28
     *
29
     * @param Name $dn
30
     */
31 66
    public function __construct(Name $dn)
32
    {
33 66
        $this->_tag = self::TAG_DIRECTORY_NAME;
34 66
        $this->_dn = $dn;
35 66
    }
36
    
37
    /**
38
     *
39
     * @param UnspecifiedType $el
40
     * @return self
41
     */
42 37
    public static function fromChosenASN1(UnspecifiedType $el): self
43
    {
44 37
        return new self(Name::fromASN1($el->asSequence()));
45
    }
46
    
47
    /**
48
     * Initialize from distinguished name string.
49
     *
50
     * @param string $str
51
     * @return self
52
     */
53 20
    public static function fromDNString(string $str): self
54
    {
55 20
        return new self(Name::fromString($str));
56
    }
57
    
58
    /**
59
     *
60
     * {@inheritdoc}
61
     */
62 3
    public function string(): string
63
    {
64 3
        return $this->_dn->toString();
65
    }
66
    
67
    /**
68
     * Get directory name.
69
     *
70
     * @return Name
71
     */
72 42
    public function dn(): Name
73
    {
74 42
        return $this->_dn;
75
    }
76
    
77
    /**
78
     *
79
     * {@inheritdoc}
80
     */
81 58
    protected function _choiceASN1(): TaggedType
82
    {
83
        // Name type is itself a CHOICE, so explicit tagging must be
84
        // employed to avoid ambiguities
85 58
        return new ExplicitlyTaggedType($this->_tag, $this->_dn->toASN1());
86
    }
87
}
88