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.
Passed
Push — master ( e19c33...8f1635 )
by Joni
03:53
created
lib/ASN1/Type/Structure.php 2 patches
Indentation   +313 added lines, -313 removed lines patch added patch discarded remove patch
@@ -13,339 +13,339 @@
 block discarded – undo
13 13
  * Base class for the constructed types.
14 14
  */
15 15
 abstract class Structure extends Element implements 
16
-    \Countable,
17
-    \IteratorAggregate
16
+	\Countable,
17
+	\IteratorAggregate
18 18
 {
19
-    use UniversalClass;
19
+	use UniversalClass;
20 20
     
21
-    /**
22
-     * Array of elements in the structure.
23
-     *
24
-     * @var Element[] $_elements
25
-     */
26
-    protected $_elements;
21
+	/**
22
+	 * Array of elements in the structure.
23
+	 *
24
+	 * @var Element[] $_elements
25
+	 */
26
+	protected $_elements;
27 27
     
28
-    /**
29
-     * Lookup table for the tagged elements.
30
-     *
31
-     * @var TaggedType[]|null $_taggedMap
32
-     */
33
-    private $_taggedMap;
28
+	/**
29
+	 * Lookup table for the tagged elements.
30
+	 *
31
+	 * @var TaggedType[]|null $_taggedMap
32
+	 */
33
+	private $_taggedMap;
34 34
     
35
-    /**
36
-     * Cache variable of elements wrapped into UnspecifiedType objects.
37
-     *
38
-     * @var UnspecifiedType[]|null $_unspecifiedTypes
39
-     */
40
-    private $_unspecifiedTypes;
35
+	/**
36
+	 * Cache variable of elements wrapped into UnspecifiedType objects.
37
+	 *
38
+	 * @var UnspecifiedType[]|null $_unspecifiedTypes
39
+	 */
40
+	private $_unspecifiedTypes;
41 41
     
42
-    /**
43
-     * Constructor.
44
-     *
45
-     * @param ElementBase ...$elements Any number of elements
46
-     */
47
-    public function __construct(ElementBase ...$elements)
48
-    {
49
-        $this->_elements = array_map(
50
-            function (ElementBase $el) {
51
-                return $el->asElement();
52
-            }, $elements);
53
-    }
42
+	/**
43
+	 * Constructor.
44
+	 *
45
+	 * @param ElementBase ...$elements Any number of elements
46
+	 */
47
+	public function __construct(ElementBase ...$elements)
48
+	{
49
+		$this->_elements = array_map(
50
+			function (ElementBase $el) {
51
+				return $el->asElement();
52
+			}, $elements);
53
+	}
54 54
     
55
-    /**
56
-     * Clone magic method.
57
-     */
58
-    public function __clone()
59
-    {
60
-        // clear cache-variables
61
-        $this->_taggedMap = null;
62
-        $this->_unspecifiedTypes = null;
63
-    }
55
+	/**
56
+	 * Clone magic method.
57
+	 */
58
+	public function __clone()
59
+	{
60
+		// clear cache-variables
61
+		$this->_taggedMap = null;
62
+		$this->_unspecifiedTypes = null;
63
+	}
64 64
     
65
-    /**
66
-     *
67
-     * @see \ASN1\Element::isConstructed()
68
-     * @return bool
69
-     */
70
-    public function isConstructed(): bool
71
-    {
72
-        return true;
73
-    }
65
+	/**
66
+	 *
67
+	 * @see \ASN1\Element::isConstructed()
68
+	 * @return bool
69
+	 */
70
+	public function isConstructed(): bool
71
+	{
72
+		return true;
73
+	}
74 74
     
75
-    /**
76
-     *
77
-     * @see \ASN1\Element::_encodedContentDER()
78
-     * @return string
79
-     */
80
-    protected function _encodedContentDER(): string
81
-    {
82
-        $data = "";
83
-        foreach ($this->_elements as $element) {
84
-            $data .= $element->toDER();
85
-        }
86
-        return $data;
87
-    }
75
+	/**
76
+	 *
77
+	 * @see \ASN1\Element::_encodedContentDER()
78
+	 * @return string
79
+	 */
80
+	protected function _encodedContentDER(): string
81
+	{
82
+		$data = "";
83
+		foreach ($this->_elements as $element) {
84
+			$data .= $element->toDER();
85
+		}
86
+		return $data;
87
+	}
88 88
     
89
-    /**
90
-     *
91
-     * {@inheritdoc}
92
-     * @see \ASN1\Element::_decodeFromDER()
93
-     * @return self
94
-     */
95
-    protected static function _decodeFromDER(Identifier $identifier, string $data,
96
-        int &$offset): ElementBase
97
-    {
98
-        $idx = $offset;
99
-        if (!$identifier->isConstructed()) {
100
-            throw new DecodeException(
101
-                "Structured element must have constructed bit set.");
102
-        }
103
-        $length = Length::expectFromDER($data, $idx);
104
-        $end = $idx + $length->intLength();
105
-        $elements = [];
106
-        while ($idx < $end) {
107
-            $elements[] = Element::fromDER($data, $idx);
108
-            // check that element didn't overflow length
109
-            if ($idx > $end) {
110
-                throw new DecodeException(
111
-                    "Structure's content overflows length.");
112
-            }
113
-        }
114
-        $offset = $idx;
115
-        // return instance by static late binding
116
-        return new static(...$elements);
117
-    }
89
+	/**
90
+	 *
91
+	 * {@inheritdoc}
92
+	 * @see \ASN1\Element::_decodeFromDER()
93
+	 * @return self
94
+	 */
95
+	protected static function _decodeFromDER(Identifier $identifier, string $data,
96
+		int &$offset): ElementBase
97
+	{
98
+		$idx = $offset;
99
+		if (!$identifier->isConstructed()) {
100
+			throw new DecodeException(
101
+				"Structured element must have constructed bit set.");
102
+		}
103
+		$length = Length::expectFromDER($data, $idx);
104
+		$end = $idx + $length->intLength();
105
+		$elements = [];
106
+		while ($idx < $end) {
107
+			$elements[] = Element::fromDER($data, $idx);
108
+			// check that element didn't overflow length
109
+			if ($idx > $end) {
110
+				throw new DecodeException(
111
+					"Structure's content overflows length.");
112
+			}
113
+		}
114
+		$offset = $idx;
115
+		// return instance by static late binding
116
+		return new static(...$elements);
117
+	}
118 118
     
119
-    /**
120
-     * Explode DER structure to DER encoded components that it contains.
121
-     *
122
-     * @param string $data
123
-     * @throws DecodeException
124
-     * @return string[]
125
-     */
126
-    public static function explodeDER(string $data): array
127
-    {
128
-        $offset = 0;
129
-        $identifier = Identifier::fromDER($data, $offset);
130
-        if (!$identifier->isConstructed()) {
131
-            throw new DecodeException("Element is not constructed.");
132
-        }
133
-        $length = Length::expectFromDER($data, $offset)->intLength();
134
-        $end = $offset + $length;
135
-        $parts = [];
136
-        while ($offset < $end) {
137
-            // start of the element
138
-            $idx = $offset;
139
-            // skip identifier
140
-            Identifier::fromDER($data, $offset);
141
-            // decode element length
142
-            $length = Length::expectFromDER($data, $offset)->intLength();
143
-            // extract der encoding of the element
144
-            $parts[] = substr($data, $idx, $offset - $idx + $length);
145
-            // update offset over content
146
-            $offset += $length;
147
-        }
148
-        return $parts;
149
-    }
119
+	/**
120
+	 * Explode DER structure to DER encoded components that it contains.
121
+	 *
122
+	 * @param string $data
123
+	 * @throws DecodeException
124
+	 * @return string[]
125
+	 */
126
+	public static function explodeDER(string $data): array
127
+	{
128
+		$offset = 0;
129
+		$identifier = Identifier::fromDER($data, $offset);
130
+		if (!$identifier->isConstructed()) {
131
+			throw new DecodeException("Element is not constructed.");
132
+		}
133
+		$length = Length::expectFromDER($data, $offset)->intLength();
134
+		$end = $offset + $length;
135
+		$parts = [];
136
+		while ($offset < $end) {
137
+			// start of the element
138
+			$idx = $offset;
139
+			// skip identifier
140
+			Identifier::fromDER($data, $offset);
141
+			// decode element length
142
+			$length = Length::expectFromDER($data, $offset)->intLength();
143
+			// extract der encoding of the element
144
+			$parts[] = substr($data, $idx, $offset - $idx + $length);
145
+			// update offset over content
146
+			$offset += $length;
147
+		}
148
+		return $parts;
149
+	}
150 150
     
151
-    /**
152
-     * Get self with an element at the given index replaced by another.
153
-     *
154
-     * @param int $idx Element index
155
-     * @param Element $el New element to insert into the structure
156
-     * @throws \OutOfBoundsException
157
-     * @return self
158
-     */
159
-    public function withReplaced(int $idx, Element $el): self
160
-    {
161
-        if (!isset($this->_elements[$idx])) {
162
-            throw new \OutOfBoundsException(
163
-                "Structure doesn't have element at index $idx.");
164
-        }
165
-        $obj = clone $this;
166
-        $obj->_elements[$idx] = $el;
167
-        return $obj;
168
-    }
151
+	/**
152
+	 * Get self with an element at the given index replaced by another.
153
+	 *
154
+	 * @param int $idx Element index
155
+	 * @param Element $el New element to insert into the structure
156
+	 * @throws \OutOfBoundsException
157
+	 * @return self
158
+	 */
159
+	public function withReplaced(int $idx, Element $el): self
160
+	{
161
+		if (!isset($this->_elements[$idx])) {
162
+			throw new \OutOfBoundsException(
163
+				"Structure doesn't have element at index $idx.");
164
+		}
165
+		$obj = clone $this;
166
+		$obj->_elements[$idx] = $el;
167
+		return $obj;
168
+	}
169 169
     
170
-    /**
171
-     * Get self with an element inserted before the given index.
172
-     *
173
-     * @param int $idx Element index
174
-     * @param Element $el New element to insert into the structure
175
-     * @throws \OutOfBoundsException
176
-     * @return self
177
-     */
178
-    public function withInserted(int $idx, Element $el): self
179
-    {
180
-        if (count($this->_elements) < $idx || $idx < 0) {
181
-            throw new \OutOfBoundsException("Index $idx is out of bounds.");
182
-        }
183
-        $obj = clone $this;
184
-        array_splice($obj->_elements, $idx, 0, [$el]);
185
-        return $obj;
186
-    }
170
+	/**
171
+	 * Get self with an element inserted before the given index.
172
+	 *
173
+	 * @param int $idx Element index
174
+	 * @param Element $el New element to insert into the structure
175
+	 * @throws \OutOfBoundsException
176
+	 * @return self
177
+	 */
178
+	public function withInserted(int $idx, Element $el): self
179
+	{
180
+		if (count($this->_elements) < $idx || $idx < 0) {
181
+			throw new \OutOfBoundsException("Index $idx is out of bounds.");
182
+		}
183
+		$obj = clone $this;
184
+		array_splice($obj->_elements, $idx, 0, [$el]);
185
+		return $obj;
186
+	}
187 187
     
188
-    /**
189
-     * Get self with an element appended to the end.
190
-     *
191
-     * @param Element $el Element to insert into the structure
192
-     * @return self
193
-     */
194
-    public function withAppended(Element $el): self
195
-    {
196
-        $obj = clone $this;
197
-        array_push($obj->_elements, $el);
198
-        return $obj;
199
-    }
188
+	/**
189
+	 * Get self with an element appended to the end.
190
+	 *
191
+	 * @param Element $el Element to insert into the structure
192
+	 * @return self
193
+	 */
194
+	public function withAppended(Element $el): self
195
+	{
196
+		$obj = clone $this;
197
+		array_push($obj->_elements, $el);
198
+		return $obj;
199
+	}
200 200
     
201
-    /**
202
-     * Get self with an element prepended in the beginning.
203
-     *
204
-     * @param Element $el Element to insert into the structure
205
-     * @return self
206
-     */
207
-    public function withPrepended(Element $el): self
208
-    {
209
-        $obj = clone $this;
210
-        array_unshift($obj->_elements, $el);
211
-        return $obj;
212
-    }
201
+	/**
202
+	 * Get self with an element prepended in the beginning.
203
+	 *
204
+	 * @param Element $el Element to insert into the structure
205
+	 * @return self
206
+	 */
207
+	public function withPrepended(Element $el): self
208
+	{
209
+		$obj = clone $this;
210
+		array_unshift($obj->_elements, $el);
211
+		return $obj;
212
+	}
213 213
     
214
-    /**
215
-     * Get self with an element at the given index removed.
216
-     *
217
-     * @param int $idx Element index
218
-     * @throws \OutOfBoundsException
219
-     * @return self
220
-     */
221
-    public function withoutElement(int $idx): self
222
-    {
223
-        if (!isset($this->_elements[$idx])) {
224
-            throw new \OutOfBoundsException(
225
-                "Structure doesn't have element at index $idx.");
226
-        }
227
-        $obj = clone $this;
228
-        array_splice($obj->_elements, $idx, 1);
229
-        return $obj;
230
-    }
214
+	/**
215
+	 * Get self with an element at the given index removed.
216
+	 *
217
+	 * @param int $idx Element index
218
+	 * @throws \OutOfBoundsException
219
+	 * @return self
220
+	 */
221
+	public function withoutElement(int $idx): self
222
+	{
223
+		if (!isset($this->_elements[$idx])) {
224
+			throw new \OutOfBoundsException(
225
+				"Structure doesn't have element at index $idx.");
226
+		}
227
+		$obj = clone $this;
228
+		array_splice($obj->_elements, $idx, 1);
229
+		return $obj;
230
+	}
231 231
     
232
-    /**
233
-     * Get elements in the structure.
234
-     *
235
-     * @return UnspecifiedType[]
236
-     */
237
-    public function elements(): array
238
-    {
239
-        if (!isset($this->_unspecifiedTypes)) {
240
-            $this->_unspecifiedTypes = array_map(
241
-                function (Element $el) {
242
-                    return new UnspecifiedType($el);
243
-                }, $this->_elements);
244
-        }
245
-        return $this->_unspecifiedTypes;
246
-    }
232
+	/**
233
+	 * Get elements in the structure.
234
+	 *
235
+	 * @return UnspecifiedType[]
236
+	 */
237
+	public function elements(): array
238
+	{
239
+		if (!isset($this->_unspecifiedTypes)) {
240
+			$this->_unspecifiedTypes = array_map(
241
+				function (Element $el) {
242
+					return new UnspecifiedType($el);
243
+				}, $this->_elements);
244
+		}
245
+		return $this->_unspecifiedTypes;
246
+	}
247 247
     
248
-    /**
249
-     * Check whether the structure has an element at the given index, optionally
250
-     * satisfying given tag expectation.
251
-     *
252
-     * @param int $idx Index 0..n
253
-     * @param int|null $expectedTag Optional type tag expectation
254
-     * @return bool
255
-     */
256
-    public function has(int $idx, $expectedTag = null): bool
257
-    {
258
-        if (!isset($this->_elements[$idx])) {
259
-            return false;
260
-        }
261
-        if (isset($expectedTag)) {
262
-            if (!$this->_elements[$idx]->isType($expectedTag)) {
263
-                return false;
264
-            }
265
-        }
266
-        return true;
267
-    }
248
+	/**
249
+	 * Check whether the structure has an element at the given index, optionally
250
+	 * satisfying given tag expectation.
251
+	 *
252
+	 * @param int $idx Index 0..n
253
+	 * @param int|null $expectedTag Optional type tag expectation
254
+	 * @return bool
255
+	 */
256
+	public function has(int $idx, $expectedTag = null): bool
257
+	{
258
+		if (!isset($this->_elements[$idx])) {
259
+			return false;
260
+		}
261
+		if (isset($expectedTag)) {
262
+			if (!$this->_elements[$idx]->isType($expectedTag)) {
263
+				return false;
264
+			}
265
+		}
266
+		return true;
267
+	}
268 268
     
269
-    /**
270
-     * Get the element at the given index, optionally checking that the element
271
-     * has a given tag.
272
-     *
273
-     * <strong>NOTE!</strong> Expectation checking is deprecated and should be
274
-     * done with <code>UnspecifiedType</code>.
275
-     *
276
-     * @param int $idx Index 0..n
277
-     * @param int|null $expectedTag Optional type tag expectation
278
-     * @throws \OutOfBoundsException If element doesn't exists
279
-     * @throws \UnexpectedValueException If expectation fails
280
-     * @return UnspecifiedType
281
-     */
282
-    public function at(int $idx, $expectedTag = null): UnspecifiedType
283
-    {
284
-        if (!isset($this->_elements[$idx])) {
285
-            throw new \OutOfBoundsException(
286
-                "Structure doesn't have an element at index $idx.");
287
-        }
288
-        $element = $this->_elements[$idx];
289
-        if (isset($expectedTag)) {
290
-            $element->expectType($expectedTag);
291
-        }
292
-        return new UnspecifiedType($element);
293
-    }
269
+	/**
270
+	 * Get the element at the given index, optionally checking that the element
271
+	 * has a given tag.
272
+	 *
273
+	 * <strong>NOTE!</strong> Expectation checking is deprecated and should be
274
+	 * done with <code>UnspecifiedType</code>.
275
+	 *
276
+	 * @param int $idx Index 0..n
277
+	 * @param int|null $expectedTag Optional type tag expectation
278
+	 * @throws \OutOfBoundsException If element doesn't exists
279
+	 * @throws \UnexpectedValueException If expectation fails
280
+	 * @return UnspecifiedType
281
+	 */
282
+	public function at(int $idx, $expectedTag = null): UnspecifiedType
283
+	{
284
+		if (!isset($this->_elements[$idx])) {
285
+			throw new \OutOfBoundsException(
286
+				"Structure doesn't have an element at index $idx.");
287
+		}
288
+		$element = $this->_elements[$idx];
289
+		if (isset($expectedTag)) {
290
+			$element->expectType($expectedTag);
291
+		}
292
+		return new UnspecifiedType($element);
293
+	}
294 294
     
295
-    /**
296
-     * Check whether the structure contains a context specific element with a
297
-     * given tag.
298
-     *
299
-     * @param int $tag Tag number
300
-     * @return bool
301
-     */
302
-    public function hasTagged(int $tag): bool
303
-    {
304
-        // lazily build lookup map
305
-        if (!isset($this->_taggedMap)) {
306
-            $this->_taggedMap = [];
307
-            foreach ($this->_elements as $element) {
308
-                if ($element->isTagged()) {
309
-                    $this->_taggedMap[$element->tag()] = $element;
310
-                }
311
-            }
312
-        }
313
-        return isset($this->_taggedMap[$tag]);
314
-    }
295
+	/**
296
+	 * Check whether the structure contains a context specific element with a
297
+	 * given tag.
298
+	 *
299
+	 * @param int $tag Tag number
300
+	 * @return bool
301
+	 */
302
+	public function hasTagged(int $tag): bool
303
+	{
304
+		// lazily build lookup map
305
+		if (!isset($this->_taggedMap)) {
306
+			$this->_taggedMap = [];
307
+			foreach ($this->_elements as $element) {
308
+				if ($element->isTagged()) {
309
+					$this->_taggedMap[$element->tag()] = $element;
310
+				}
311
+			}
312
+		}
313
+		return isset($this->_taggedMap[$tag]);
314
+	}
315 315
     
316
-    /**
317
-     * Get a context specific element tagged with a given tag.
318
-     *
319
-     * @param int $tag
320
-     * @throws \LogicException If tag doesn't exists
321
-     * @return TaggedType
322
-     */
323
-    public function getTagged(int $tag): TaggedType
324
-    {
325
-        if (!$this->hasTagged($tag)) {
326
-            throw new \LogicException("No tagged element for tag $tag.");
327
-        }
328
-        return $this->_taggedMap[$tag];
329
-    }
316
+	/**
317
+	 * Get a context specific element tagged with a given tag.
318
+	 *
319
+	 * @param int $tag
320
+	 * @throws \LogicException If tag doesn't exists
321
+	 * @return TaggedType
322
+	 */
323
+	public function getTagged(int $tag): TaggedType
324
+	{
325
+		if (!$this->hasTagged($tag)) {
326
+			throw new \LogicException("No tagged element for tag $tag.");
327
+		}
328
+		return $this->_taggedMap[$tag];
329
+	}
330 330
     
331
-    /**
332
-     *
333
-     * @see \Countable::count()
334
-     * @return int
335
-     */
336
-    public function count(): int
337
-    {
338
-        return count($this->_elements);
339
-    }
331
+	/**
332
+	 *
333
+	 * @see \Countable::count()
334
+	 * @return int
335
+	 */
336
+	public function count(): int
337
+	{
338
+		return count($this->_elements);
339
+	}
340 340
     
341
-    /**
342
-     * Get an iterator for the UnspecifiedElement objects.
343
-     *
344
-     * @see \IteratorAggregate::getIterator()
345
-     * @return \ArrayIterator
346
-     */
347
-    public function getIterator(): \ArrayIterator
348
-    {
349
-        return new \ArrayIterator($this->elements());
350
-    }
341
+	/**
342
+	 * Get an iterator for the UnspecifiedElement objects.
343
+	 *
344
+	 * @see \IteratorAggregate::getIterator()
345
+	 * @return \ArrayIterator
346
+	 */
347
+	public function getIterator(): \ArrayIterator
348
+	{
349
+		return new \ArrayIterator($this->elements());
350
+	}
351 351
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(strict_types = 1);
2
+declare(strict_types=1);
3 3
 
4 4
 namespace ASN1\Type;
5 5
 
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
     public function __construct(ElementBase ...$elements)
48 48
     {
49 49
         $this->_elements = array_map(
50
-            function (ElementBase $el) {
50
+            function(ElementBase $el) {
51 51
                 return $el->asElement();
52 52
             }, $elements);
53 53
     }
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
     {
239 239
         if (!isset($this->_unspecifiedTypes)) {
240 240
             $this->_unspecifiedTypes = array_map(
241
-                function (Element $el) {
241
+                function(Element $el) {
242 242
                     return new UnspecifiedType($el);
243 243
                 }, $this->_elements);
244 244
         }
Please login to merge, or discard this patch.