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.
Completed
Branch php72 (a7f01e)
by Joni
04:53
created

GeneralSubtree   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
eloc 24
dl 0
loc 85
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A fromASN1() 0 14 3
A base() 0 3 1
A toASN1() 0 10 4
A __construct() 0 5 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\X509\Certificate\Extension\NameConstraints;
6
7
use Sop\ASN1\Element;
8
use Sop\ASN1\Type\Constructed\Sequence;
9
use Sop\ASN1\Type\Primitive\Integer;
10
use Sop\ASN1\Type\Tagged\ImplicitlyTaggedType;
11
use Sop\X509\GeneralName\GeneralName;
12
13
/**
14
 * Implements <i>GeneralSubtree</i> ASN.1 type used by
15
 * 'Name Constraints' certificate extension.
16
 *
17
 * @see https://tools.ietf.org/html/rfc5280#section-4.2.1.10
18
 */
19
class GeneralSubtree
20
{
21
    /**
22
     * Constraint.
23
     *
24
     * @var GeneralName
25
     */
26
    protected $_base;
27
28
    /**
29
     * Not used, must be zero.
30
     *
31
     * @var int
32
     */
33
    protected $_min;
34
35
    /**
36
     * Not used, must be null.
37
     *
38
     * @var null|int
39
     */
40
    protected $_max;
41
42
    /**
43
     * Constructor.
44
     *
45
     * @param GeneralName $base
46
     * @param int         $min
47
     * @param null|int    $max
48
     */
49 17
    public function __construct(GeneralName $base, int $min = 0, ?int $max = null)
50
    {
51 17
        $this->_base = $base;
52 17
        $this->_min = $min;
53 17
        $this->_max = $max;
54 17
    }
55
56
    /**
57
     * Initialize from ASN.1.
58
     *
59
     * @param Sequence $seq
60
     *
61
     * @return self
62
     */
63 12
    public static function fromASN1(Sequence $seq): self
64
    {
65 12
        $base = GeneralName::fromASN1($seq->at(0)->asTagged());
66 12
        $min = 0;
67 12
        $max = null;
68 12
        if ($seq->hasTagged(0)) {
69 1
            $min = $seq->getTagged(0)->asImplicit(Element::TYPE_INTEGER)
70 1
                ->asInteger()->intNumber();
71
        }
72 12
        if ($seq->hasTagged(1)) {
73 1
            $max = $seq->getTagged(1)->asImplicit(Element::TYPE_INTEGER)
74 1
                ->asInteger()->intNumber();
75
        }
76 12
        return new self($base, $min, $max);
77
    }
78
79
    /**
80
     * Get constraint.
81
     *
82
     * @return GeneralName
83
     */
84 5
    public function base(): GeneralName
85
    {
86 5
        return $this->_base;
87
    }
88
89
    /**
90
     * Generate ASN.1 structure.
91
     *
92
     * @return Sequence
93
     */
94 19
    public function toASN1(): Sequence
95
    {
96 19
        $elements = [$this->_base->toASN1()];
97 19
        if (isset($this->_min) && 0 !== $this->_min) {
98 1
            $elements[] = new ImplicitlyTaggedType(0, new Integer($this->_min));
99
        }
100 19
        if (isset($this->_max)) {
101 1
            $elements[] = new ImplicitlyTaggedType(1, new Integer($this->_max));
102
        }
103 19
        return new Sequence(...$elements);
104
    }
105
}
106