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.

NameConstraintsExtension::excludedSubtrees()   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;
6
7
use Sop\ASN1\Element;
8
use Sop\ASN1\Type\Constructed\Sequence;
9
use Sop\ASN1\Type\Tagged\ImplicitlyTaggedType;
10
use Sop\ASN1\Type\UnspecifiedType;
11
use Sop\X509\Certificate\Extension\NameConstraints\GeneralSubtrees;
12
13
/**
14
 * Implements 'Name Constraints' certificate extension.
15
 *
16
 * @see https://tools.ietf.org/html/rfc5280#section-4.2.1.10
17
 */
18
class NameConstraintsExtension extends Extension
19
{
20
    /**
21
     * Permitted subtrees.
22
     *
23
     * @var null|GeneralSubtrees
24
     */
25
    protected $_permitted;
26
27
    /**
28
     * Excluded subtrees.
29
     *
30
     * @var null|GeneralSubtrees
31
     */
32
    protected $_excluded;
33
34
    /**
35
     * Constructor.
36
     *
37
     * @param bool            $critical
38
     * @param GeneralSubtrees $permitted
39
     * @param GeneralSubtrees $excluded
40
     */
41 12
    public function __construct(bool $critical, ?GeneralSubtrees $permitted = null,
42
        ?GeneralSubtrees $excluded = null)
43
    {
44 12
        parent::__construct(self::OID_NAME_CONSTRAINTS, $critical);
45 12
        $this->_permitted = $permitted;
46 12
        $this->_excluded = $excluded;
47 12
    }
48
49
    /**
50
     * Whether permitted subtrees are present.
51
     *
52
     * @return bool
53
     */
54 3
    public function hasPermittedSubtrees(): bool
55
    {
56 3
        return isset($this->_permitted);
57
    }
58
59
    /**
60
     * Get permitted subtrees.
61
     *
62
     * @throws \LogicException If not set
63
     *
64
     * @return GeneralSubtrees
65
     */
66 3
    public function permittedSubtrees(): GeneralSubtrees
67
    {
68 3
        if (!$this->hasPermittedSubtrees()) {
69 1
            throw new \LogicException('No permitted subtrees.');
70
        }
71 2
        return $this->_permitted;
72
    }
73
74
    /**
75
     * Whether excluded subtrees are present.
76
     *
77
     * @return bool
78
     */
79 2
    public function hasExcludedSubtrees(): bool
80
    {
81 2
        return isset($this->_excluded);
82
    }
83
84
    /**
85
     * Get excluded subtrees.
86
     *
87
     * @throws \LogicException If not set
88
     *
89
     * @return GeneralSubtrees
90
     */
91 2
    public function excludedSubtrees(): GeneralSubtrees
92
    {
93 2
        if (!$this->hasExcludedSubtrees()) {
94 1
            throw new \LogicException('No excluded subtrees.');
95
        }
96 1
        return $this->_excluded;
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102 10
    protected static function _fromDER(string $data, bool $critical): Extension
103
    {
104 10
        $seq = UnspecifiedType::fromDER($data)->asSequence();
105 10
        $permitted = null;
106 10
        $excluded = null;
107 10
        if ($seq->hasTagged(0)) {
108 9
            $permitted = GeneralSubtrees::fromASN1(
109 9
                $seq->getTagged(0)->asImplicit(Element::TYPE_SEQUENCE)->asSequence());
110
        }
111 10
        if ($seq->hasTagged(1)) {
112 1
            $excluded = GeneralSubtrees::fromASN1(
113 1
                $seq->getTagged(1)->asImplicit(Element::TYPE_SEQUENCE)->asSequence());
114
        }
115 10
        return new self($critical, $permitted, $excluded);
116
    }
117
118
    /**
119
     * {@inheritdoc}
120
     */
121 17
    protected function _valueASN1(): Element
122
    {
123 17
        $elements = [];
124 17
        if (isset($this->_permitted)) {
125 16
            $elements[] = new ImplicitlyTaggedType(0, $this->_permitted->toASN1());
126
        }
127 17
        if (isset($this->_excluded)) {
128 1
            $elements[] = new ImplicitlyTaggedType(1, $this->_excluded->toASN1());
129
        }
130 17
        return new Sequence(...$elements);
131
    }
132
}
133