GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

DistributionPoint::fullName()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\X509\Certificate\Extension\DistributionPoint;
6
7
use Sop\ASN1\Element;
8
use Sop\ASN1\Type\Constructed\Sequence;
9
use Sop\ASN1\Type\Tagged\ExplicitlyTaggedType;
10
use Sop\ASN1\Type\Tagged\ImplicitlyTaggedType;
11
use Sop\X509\GeneralName\GeneralNames;
12
13
/**
14
 * Implements *DistributionPoint* ASN.1 type used by 'CRL Distribution Points'
15
 * certificate extension.
16
 *
17
 * @see https://tools.ietf.org/html/rfc5280#section-4.2.1.13
18
 */
19
class DistributionPoint
20
{
21
    /**
22
     * Distribution point name.
23
     *
24
     * @var null|DistributionPointName
25
     */
26
    protected $_distributionPoint;
27
28
    /**
29
     * Revocation reason.
30
     *
31
     * @var null|ReasonFlags
32
     */
33
    protected $_reasons;
34
35
    /**
36
     * CRL issuer.
37
     *
38
     * @var null|GeneralNames
39
     */
40
    protected $_issuer;
41
42
    /**
43
     * Constructor.
44
     *
45
     * @param null|DistributionPointName $name
46
     * @param null|ReasonFlags           $reasons
47
     * @param null|GeneralNames          $issuer
48
     */
49 17
    public function __construct(?DistributionPointName $name = null,
50
        ?ReasonFlags $reasons = null, ?GeneralNames $issuer = null)
51
    {
52 17
        $this->_distributionPoint = $name;
53 17
        $this->_reasons = $reasons;
54 17
        $this->_issuer = $issuer;
55 17
    }
56
57
    /**
58
     * Initialize from ASN.1.
59
     *
60
     * @param Sequence $seq
61
     *
62
     * @return self
63
     */
64 12
    public static function fromASN1(Sequence $seq): self
65
    {
66 12
        $name = null;
67 12
        $reasons = null;
68 12
        $issuer = null;
69 12
        if ($seq->hasTagged(0)) {
70
            // promoted to explicit tagging because underlying type is CHOICE
71 12
            $name = DistributionPointName::fromTaggedType(
72 12
                $seq->getTagged(0)->asExplicit()->asTagged());
73
        }
74 12
        if ($seq->hasTagged(1)) {
75 11
            $reasons = ReasonFlags::fromASN1(
76 11
                $seq->getTagged(1)->asImplicit(Element::TYPE_BIT_STRING)
77 11
                    ->asBitString());
78
        }
79 12
        if ($seq->hasTagged(2)) {
80 11
            $issuer = GeneralNames::fromASN1(
81 11
                $seq->getTagged(2)->asImplicit(Element::TYPE_SEQUENCE)
82 11
                    ->asSequence());
83
        }
84 12
        return new self($name, $reasons, $issuer);
85
    }
86
87
    /**
88
     * Check whether distribution point name is set.
89
     *
90
     * @return bool
91
     */
92 9
    public function hasDistributionPointName(): bool
93
    {
94 9
        return isset($this->_distributionPoint);
95
    }
96
97
    /**
98
     * Get distribution point name.
99
     *
100
     * @throws \LogicException If not set
101
     *
102
     * @return DistributionPointName
103
     */
104 9
    public function distributionPointName(): DistributionPointName
105
    {
106 9
        if (!$this->hasDistributionPointName()) {
107 1
            throw new \LogicException('distributionPoint not set.');
108
        }
109 8
        return $this->_distributionPoint;
110
    }
111
112
    /**
113
     * Check whether distribution point name is set and it's a full name.
114
     *
115
     * @return bool
116
     */
117 3
    public function hasFullName(): bool
118
    {
119 3
        return DistributionPointName::TAG_FULL_NAME ===
120 3
             $this->distributionPointName()->tag();
121
    }
122
123
    /**
124
     * Get full distribution point name.
125
     *
126
     * @throws \LogicException If not set
127
     *
128
     * @return FullName
129
     */
130 3
    public function fullName(): FullName
131
    {
132 3
        if (!$this->hasFullName()) {
133 1
            throw new \LogicException('fullName not set.');
134
        }
135 2
        return $this->_distributionPoint;
136
    }
137
138
    /**
139
     * Check whether distribution point name is set and it's a relative name.
140
     *
141
     * @return bool
142
     */
143 2
    public function hasRelativeName(): bool
144
    {
145 2
        return DistributionPointName::TAG_RDN ===
146 2
             $this->distributionPointName()->tag();
147
    }
148
149
    /**
150
     * Get relative distribution point name.
151
     *
152
     * @throws \LogicException If not set
153
     *
154
     * @return RelativeName
155
     */
156 2
    public function relativeName(): RelativeName
157
    {
158 2
        if (!$this->hasRelativeName()) {
159 1
            throw new \LogicException('nameRelativeToCRLIssuer not set.');
160
        }
161 1
        return $this->_distributionPoint;
162
    }
163
164
    /**
165
     * Check whether reasons flags is set.
166
     *
167
     * @return bool
168
     */
169 5
    public function hasReasons(): bool
170
    {
171 5
        return isset($this->_reasons);
172
    }
173
174
    /**
175
     * Get revocation reason flags.
176
     *
177
     * @throws \LogicException If not set
178
     *
179
     * @return ReasonFlags
180
     */
181 5
    public function reasons(): ReasonFlags
182
    {
183 5
        if (!$this->hasReasons()) {
184 1
            throw new \LogicException('reasons not set.');
185
        }
186 4
        return $this->_reasons;
187
    }
188
189
    /**
190
     * Check whether cRLIssuer is set.
191
     *
192
     * @return bool
193
     */
194 5
    public function hasCRLIssuer(): bool
195
    {
196 5
        return isset($this->_issuer);
197
    }
198
199
    /**
200
     * Get CRL issuer.
201
     *
202
     * @throws \LogicException If not set
203
     *
204
     * @return GeneralNames
205
     */
206 5
    public function crlIssuer(): GeneralNames
207
    {
208 5
        if (!$this->hasCRLIssuer()) {
209 1
            throw new \LogicException('crlIssuer not set.');
210
        }
211 4
        return $this->_issuer;
212
    }
213
214
    /**
215
     * Generate ASN.1 structure.
216
     *
217
     * @return Sequence
218
     */
219 18
    public function toASN1(): Sequence
220
    {
221 18
        $elements = [];
222 18
        if (isset($this->_distributionPoint)) {
223 18
            $elements[] = new ExplicitlyTaggedType(0,
224 18
                $this->_distributionPoint->toASN1());
225
        }
226 18
        if (isset($this->_reasons)) {
227 17
            $elements[] = new ImplicitlyTaggedType(1, $this->_reasons->toASN1());
228
        }
229 18
        if (isset($this->_issuer)) {
230 17
            $elements[] = new ImplicitlyTaggedType(2, $this->_issuer->toASN1());
231
        }
232 18
        return new Sequence(...$elements);
233
    }
234
}
235