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
Pull Request — master (#1)
by thomas
05:34
created

IetfAttrSyntax   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 201
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 18
lcom 1
cbo 8
dl 0
loc 201
ccs 0
cts 63
cp 0
rs 10
c 1
b 0
f 0

14 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A fromASN1() 0 23 2
A withPolicyAuthority() 0 6 1
A hasPolicyAuthority() 0 4 1
A policyAuthority() 0 7 2
A values() 0 4 1
A first() 0 7 2
A toASN1() 0 14 2
A stringValue() 0 4 1
A equalityMatchingRule() 0 4 1
A rfc2253String() 0 4 1
A _transcodedString() 0 4 1
A count() 0 4 1
A getIterator() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace X509\AttributeCertificate\Attribute;
6
7
use ASN1\Element;
8
use ASN1\Type\UnspecifiedType;
9
use ASN1\Type\Constructed\Sequence;
10
use ASN1\Type\Tagged\ImplicitlyTaggedType;
11
use X501\ASN1\AttributeValue\AttributeValue;
12
use X501\MatchingRule\BinaryMatch;
13
use X509\GeneralName\GeneralNames;
14
15
/**
16
 * Base class implementing <i>IetfAttrSyntax</i> ASN.1 type used by
17
 * attribute certificate attribute values.
18
 *
19
 * @link https://tools.ietf.org/html/rfc5755#section-4.4
20
 */
21
abstract class IetfAttrSyntax extends AttributeValue implements 
22
    \Countable,
23
    \IteratorAggregate
24
{
25
    /**
26
     * Policy authority.
27
     *
28
     * @var GeneralNames|null $_policyAuthority
29
     */
30
    protected $_policyAuthority;
31
    
32
    /**
33
     * Values.
34
     *
35
     * @var IetfAttrValue[] $_values
36
     */
37
    protected $_values;
38
    
39
    /**
40
     * Constructor.
41
     *
42
     * @param IetfAttrValue[] $values
43
     */
44
    public function __construct(IetfAttrValue ...$values)
45
    {
46
        $this->_policyAuthority = null;
47
        $this->_values = $values;
0 ignored issues
show
Documentation Bug introduced by
It seems like $values of type array<integer,array<inte...ribute\IetfAttrValue>>> is incompatible with the declared type array<integer,object<X50...tribute\IetfAttrValue>> of property $_values.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
48
    }
49
    
50
    /**
51
     *
52
     * @param UnspecifiedType $el
53
     * @return self
54
     */
55
    public static function fromASN1(UnspecifiedType $el)
56
    {
57
        $seq = $el->asSequence();
58
        $authority = null;
59
        $idx = 0;
60
        if ($seq->hasTagged(0)) {
61
            $authority = GeneralNames::fromASN1(
62
                $seq->getTagged(0)
63
                    ->asImplicit(Element::TYPE_SEQUENCE)
64
                    ->asSequence());
65
            ++$idx;
66
        }
67
        $values = array_map(
68
            function (UnspecifiedType $el) {
69
                return IetfAttrValue::fromASN1($el);
70
            },
71
            $seq->at($idx)
72
                ->asSequence()
73
                ->elements());
74
        $obj = new static(...$values);
75
        $obj->_policyAuthority = $authority;
76
        return $obj;
77
    }
78
    
79
    /**
80
     * Get self with policy authority.
81
     *
82
     * @param GeneralNames $names
83
     * @return self
84
     */
85
    public function withPolicyAuthority(GeneralNames $names)
86
    {
87
        $obj = clone $this;
88
        $obj->_policyAuthority = $names;
89
        return $obj;
90
    }
91
    
92
    /**
93
     * Check whether policy authority is present.
94
     *
95
     * @return bool
96
     */
97
    public function hasPolicyAuthority(): bool
98
    {
99
        return isset($this->_policyAuthority);
100
    }
101
    
102
    /**
103
     * Get policy authority.
104
     *
105
     * @throws \LogicException
106
     * @return GeneralNames
107
     */
108
    public function policyAuthority(): GeneralNames
109
    {
110
        if (!$this->hasPolicyAuthority()) {
111
            throw new \LogicException("policyAuthority not set.");
112
        }
113
        return $this->_policyAuthority;
114
    }
115
    
116
    /**
117
     * Get values.
118
     *
119
     * @return IetfAttrValue[]
120
     */
121
    public function values(): array
122
    {
123
        return $this->_values;
124
    }
125
    
126
    /**
127
     * Get first value.
128
     *
129
     * @throws \LogicException
130
     * @return IetfAttrValue
131
     */
132
    public function first(): IetfAttrValue
133
    {
134
        if (!count($this->_values)) {
135
            throw new \LogicException("No values.");
136
        }
137
        return $this->_values[0];
138
    }
139
    
140
    /**
141
     *
142
     * @see \X501\ASN1\AttributeValue\AttributeValue::toASN1()
143
     * @return Sequence
144
     */
145
    public function toASN1(): Sequence
146
    {
147
        $elements = array();
148
        if (isset($this->_policyAuthority)) {
149
            $elements[] = new ImplicitlyTaggedType(0,
150
                $this->_policyAuthority->toASN1());
151
        }
152
        $values = array_map(
153
            function (IetfAttrValue $val) {
154
                return $val->toASN1();
155
            }, $this->_values);
156
        $elements[] = new Sequence(...$values);
157
        return new Sequence(...$elements);
158
    }
159
    
160
    /**
161
     *
162
     * @see \X501\ASN1\AttributeValue\AttributeValue::stringValue()
163
     * @return string
164
     */
165
    public function stringValue(): string
166
    {
167
        return "#" . bin2hex($this->toASN1()->toDER());
168
    }
169
    
170
    /**
171
     *
172
     * @see \X501\ASN1\AttributeValue\AttributeValue::equalityMatchingRule()
173
     * @return BinaryMatch
174
     */
175
    public function equalityMatchingRule(): BinaryMatch
176
    {
177
        return new BinaryMatch();
178
    }
179
    
180
    /**
181
     *
182
     * @see \X501\ASN1\AttributeValue\AttributeValue::rfc2253String()
183
     * @return string
184
     */
185
    public function rfc2253String(): string
186
    {
187
        return $this->stringValue();
188
    }
189
    
190
    /**
191
     *
192
     * @see \X501\ASN1\AttributeValue\AttributeValue::_transcodedString()
193
     * @return string
194
     */
195
    protected function _transcodedString(): string
196
    {
197
        return $this->stringValue();
198
    }
199
    
200
    /**
201
     * Get number of values.
202
     *
203
     * @see \Countable::count()
204
     * @return int
205
     */
206
    public function count(): int
207
    {
208
        return count($this->_values);
209
    }
210
    
211
    /**
212
     * Get iterator for values.
213
     *
214
     * @see \IteratorAggregate::getIterator()
215
     * @return \ArrayIterator
216
     */
217
    public function getIterator(): \ArrayIterator
218
    {
219
        return new \ArrayIterator($this->_values);
220
    }
221
}
222