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.
Test Failed
Push — master ( 405cf3...79c9ba )
by Joni
04:48
created

BasicConstraintsExtension   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
eloc 26
dl 0
loc 96
ccs 29
cts 29
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A hasPathLen() 0 3 1
A __construct() 0 5 1
A isCA() 0 3 1
A _valueASN1() 0 10 3
A _fromDER() 0 13 3
A pathLen() 0 6 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\Primitive\Boolean;
10
use Sop\ASN1\Type\Primitive\Integer;
11
use Sop\ASN1\Type\UnspecifiedType;
12
13
/**
14
 * Implements 'Basic Constraints' certificate extension.
15
 *
16
 * @see https://tools.ietf.org/html/rfc5280#section-4.2.1.9
17
 */
18
class BasicConstraintsExtension extends Extension
19
{
20
    /**
21
     * Whether certificate is a CA.
22
     *
23
     * @var bool
24
     */
25
    protected $_ca;
26
27
    /**
28
     * Maximum certification path length.
29
     *
30
     * @var null|int
31
     */
32
    protected $_pathLen;
33
34
    /**
35
     * Constructor.
36
     *
37
     * @param bool     $critical
38
     * @param bool     $ca
39
     * @param null|int $path_len
40
     */
41 23
    public function __construct(bool $critical, bool $ca, ?int $path_len = null)
42
    {
43 23
        parent::__construct(self::OID_BASIC_CONSTRAINTS, $critical);
44 23
        $this->_ca = $ca;
45 23
        $this->_pathLen = $path_len;
46 23
    }
47
48
    /**
49
     * Whether certificate is a CA.
50
     *
51
     * @return bool
52
     */
53 15
    public function isCA(): bool
54
    {
55 15
        return $this->_ca;
56 15
    }
57 15
58 15
    /**
59 15
     * Whether path length is present.
60 14
     *
61 14
     * @return bool
62 14
     */
63
    public function hasPathLen(): bool
64 15
    {
65 14
        return isset($this->_pathLen);
66 14
    }
67 14
68
    /**
69 15
     * Get path length.
70
     *
71
     * @throws \LogicException If not set
72
     *
73
     * @return int
74
     */
75
    public function pathLen(): int
76
    {
77 40
        if (!$this->hasPathLen()) {
78
            throw new \LogicException('pathLenConstraint not set.');
79 40
        }
80
        return $this->_pathLen;
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86
    protected static function _fromDER(string $data, bool $critical): Extension
87 40
    {
88
        $seq = UnspecifiedType::fromDER($data)->asSequence();
89 40
        $ca = false;
90
        $path_len = null;
91
        $idx = 0;
92
        if ($seq->has($idx, Element::TYPE_BOOLEAN)) {
93
            $ca = $seq->at($idx++)->asBoolean()->value();
94
        }
95
        if ($seq->has($idx, Element::TYPE_INTEGER)) {
96
            $path_len = $seq->at($idx)->asInteger()->intNumber();
97
        }
98 29
        return new self($critical, $ca, $path_len);
99
    }
100 29
101 1
    /**
102
     * {@inheritdoc}
103 28
     */
104
    protected function _valueASN1(): Element
105
    {
106
        $elements = [];
107
        if ($this->_ca) {
108
            $elements[] = new Boolean(true);
109
        }
110
        if (isset($this->_pathLen)) {
111 47
            $elements[] = new Integer($this->_pathLen);
112
        }
113 47
        return new Sequence(...$elements);
114 47
    }
115
}
116