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::fromASN1()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 14
ccs 11
cts 11
cp 1
rs 9.9332
c 0
b 0
f 0
cc 3
nc 4
nop 1
crap 3
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