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

PolicyConstraintsExtension   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 111
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 13
eloc 32
dl 0
loc 111
ccs 37
cts 37
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A inhibitPolicyMapping() 0 6 2
A hasInhibitPolicyMapping() 0 3 1
A hasRequireExplicitPolicy() 0 3 1
A __construct() 0 6 1
A _valueASN1() 0 12 3
A _fromDER() 0 14 3
A requireExplicitPolicy() 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\Integer;
10
use Sop\ASN1\Type\Tagged\ImplicitlyTaggedType;
11
use Sop\ASN1\Type\UnspecifiedType;
12
13
/**
14
 * Implements 'Policy Constraints' certificate extensions.
15
 *
16
 * @see https://tools.ietf.org/html/rfc5280#section-4.2.1.11
17
 */
18
class PolicyConstraintsExtension extends Extension
19
{
20
    /**
21
     * @var null|int
22
     */
23
    protected $_requireExplicitPolicy;
24
25
    /**
26
     * @var null|int
27
     */
28
    protected $_inhibitPolicyMapping;
29
30
    /**
31
     * Constructor.
32
     *
33
     * @param bool     $critical
34
     * @param null|int $require_explicit_policy
35
     * @param null|int $inhibit_policy_mapping
36
     */
37 12
    public function __construct(bool $critical,
38
        ?int $require_explicit_policy = null, ?int $inhibit_policy_mapping = null)
39
    {
40 12
        parent::__construct(self::OID_POLICY_CONSTRAINTS, $critical);
41 12
        $this->_requireExplicitPolicy = $require_explicit_policy;
42 12
        $this->_inhibitPolicyMapping = $inhibit_policy_mapping;
43 12
    }
44
45
    /**
46
     * Whether requireExplicitPolicy is present.
47
     *
48
     * @return bool
49
     */
50 18
    public function hasRequireExplicitPolicy(): bool
51
    {
52 18
        return isset($this->_requireExplicitPolicy);
53
    }
54
55
    /**
56
     * Get requireExplicitPolicy.
57
     *
58
     * @throws \LogicException If not set
59
     *
60
     * @return int
61
     */
62 18
    public function requireExplicitPolicy(): int
63
    {
64 18
        if (!$this->hasRequireExplicitPolicy()) {
65 1
            throw new \LogicException('requireExplicitPolicy not set.');
66
        }
67 17
        return $this->_requireExplicitPolicy;
1 ignored issue
show
Bug Best Practice introduced by
The expression return $this->_requireExplicitPolicy could return the type null which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
68
    }
69
70
    /**
71
     * Whether inhibitPolicyMapping is present.
72
     *
73
     * @return bool
74
     */
75 5
    public function hasInhibitPolicyMapping(): bool
76
    {
77 5
        return isset($this->_inhibitPolicyMapping);
78
    }
79
80
    /**
81
     * Get inhibitPolicyMapping.
82
     *
83
     * @throws \LogicException If not set
84
     *
85
     * @return int
86
     */
87 4
    public function inhibitPolicyMapping(): int
88
    {
89 4
        if (!$this->hasInhibitPolicyMapping()) {
90 1
            throw new \LogicException('inhibitPolicyMapping not set.');
91
        }
92 3
        return $this->_inhibitPolicyMapping;
1 ignored issue
show
Bug Best Practice introduced by
The expression return $this->_inhibitPolicyMapping could return the type null which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
93
    }
94
95
    /**
96
     * {@inheritdoc}
97
     */
98 10
    protected static function _fromDER(string $data, bool $critical): Extension
99
    {
100 10
        $seq = UnspecifiedType::fromDER($data)->asSequence();
101 10
        $require_explicit_policy = null;
102 10
        $inhibit_policy_mapping = null;
103 10
        if ($seq->hasTagged(0)) {
104 9
            $require_explicit_policy = $seq->getTagged(0)
105 9
                ->asImplicit(Element::TYPE_INTEGER)->asInteger()->intNumber();
106
        }
107 10
        if ($seq->hasTagged(1)) {
108 9
            $inhibit_policy_mapping = $seq->getTagged(1)
109 9
                ->asImplicit(Element::TYPE_INTEGER)->asInteger()->intNumber();
110
        }
111 10
        return new self($critical, $require_explicit_policy, $inhibit_policy_mapping);
112
    }
113
114
    /**
115
     * {@inheritdoc}
116
     */
117 19
    protected function _valueASN1(): Element
118
    {
119 19
        $elements = [];
120 19
        if (isset($this->_requireExplicitPolicy)) {
121 18
            $elements[] = new ImplicitlyTaggedType(0,
122 18
                new Integer($this->_requireExplicitPolicy));
123
        }
124 19
        if (isset($this->_inhibitPolicyMapping)) {
125 16
            $elements[] = new ImplicitlyTaggedType(1,
126 16
                new Integer($this->_inhibitPolicyMapping));
127
        }
128 19
        return new Sequence(...$elements);
129
    }
130
}
131