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
Branch php72 (57c34e)
by Joni
05:01
created
lib/ASN1/Element.php 3 patches
Indentation   +436 added lines, -436 removed lines patch added patch discarded remove patch
@@ -23,467 +23,467 @@
 block discarded – undo
23 23
  */
24 24
 abstract class Element implements ElementBase
25 25
 {
26
-    // Universal type tags
27
-    const TYPE_EOC = 0x00;
28
-    const TYPE_BOOLEAN = 0x01;
29
-    const TYPE_INTEGER = 0x02;
30
-    const TYPE_BIT_STRING = 0x03;
31
-    const TYPE_OCTET_STRING = 0x04;
32
-    const TYPE_NULL = 0x05;
33
-    const TYPE_OBJECT_IDENTIFIER = 0x06;
34
-    const TYPE_OBJECT_DESCRIPTOR = 0x07;
35
-    const TYPE_EXTERNAL = 0x08;
36
-    const TYPE_REAL = 0x09;
37
-    const TYPE_ENUMERATED = 0x0a;
38
-    const TYPE_EMBEDDED_PDV = 0x0b;
39
-    const TYPE_UTF8_STRING = 0x0c;
40
-    const TYPE_RELATIVE_OID = 0x0d;
41
-    const TYPE_SEQUENCE = 0x10;
42
-    const TYPE_SET = 0x11;
43
-    const TYPE_NUMERIC_STRING = 0x12;
44
-    const TYPE_PRINTABLE_STRING = 0x13;
45
-    const TYPE_T61_STRING = 0x14;
46
-    const TYPE_VIDEOTEX_STRING = 0x15;
47
-    const TYPE_IA5_STRING = 0x16;
48
-    const TYPE_UTC_TIME = 0x17;
49
-    const TYPE_GENERALIZED_TIME = 0x18;
50
-    const TYPE_GRAPHIC_STRING = 0x19;
51
-    const TYPE_VISIBLE_STRING = 0x1a;
52
-    const TYPE_GENERAL_STRING = 0x1b;
53
-    const TYPE_UNIVERSAL_STRING = 0x1c;
54
-    const TYPE_CHARACTER_STRING = 0x1d;
55
-    const TYPE_BMP_STRING = 0x1e;
26
+	// Universal type tags
27
+	const TYPE_EOC = 0x00;
28
+	const TYPE_BOOLEAN = 0x01;
29
+	const TYPE_INTEGER = 0x02;
30
+	const TYPE_BIT_STRING = 0x03;
31
+	const TYPE_OCTET_STRING = 0x04;
32
+	const TYPE_NULL = 0x05;
33
+	const TYPE_OBJECT_IDENTIFIER = 0x06;
34
+	const TYPE_OBJECT_DESCRIPTOR = 0x07;
35
+	const TYPE_EXTERNAL = 0x08;
36
+	const TYPE_REAL = 0x09;
37
+	const TYPE_ENUMERATED = 0x0a;
38
+	const TYPE_EMBEDDED_PDV = 0x0b;
39
+	const TYPE_UTF8_STRING = 0x0c;
40
+	const TYPE_RELATIVE_OID = 0x0d;
41
+	const TYPE_SEQUENCE = 0x10;
42
+	const TYPE_SET = 0x11;
43
+	const TYPE_NUMERIC_STRING = 0x12;
44
+	const TYPE_PRINTABLE_STRING = 0x13;
45
+	const TYPE_T61_STRING = 0x14;
46
+	const TYPE_VIDEOTEX_STRING = 0x15;
47
+	const TYPE_IA5_STRING = 0x16;
48
+	const TYPE_UTC_TIME = 0x17;
49
+	const TYPE_GENERALIZED_TIME = 0x18;
50
+	const TYPE_GRAPHIC_STRING = 0x19;
51
+	const TYPE_VISIBLE_STRING = 0x1a;
52
+	const TYPE_GENERAL_STRING = 0x1b;
53
+	const TYPE_UNIVERSAL_STRING = 0x1c;
54
+	const TYPE_CHARACTER_STRING = 0x1d;
55
+	const TYPE_BMP_STRING = 0x1e;
56 56
 
57
-    /**
58
-     * Mapping from universal type tag to implementation class name.
59
-     *
60
-     * @internal
61
-     *
62
-     * @var array
63
-     */
64
-    const MAP_TAG_TO_CLASS = [
65
-        self::TYPE_EOC => Primitive\EOC::class,
66
-        self::TYPE_BOOLEAN => Primitive\Boolean::class,
67
-        self::TYPE_INTEGER => Primitive\Integer::class,
68
-        self::TYPE_BIT_STRING => Primitive\BitString::class,
69
-        self::TYPE_OCTET_STRING => Primitive\OctetString::class,
70
-        self::TYPE_NULL => Primitive\NullType::class,
71
-        self::TYPE_OBJECT_IDENTIFIER => Primitive\ObjectIdentifier::class,
72
-        self::TYPE_OBJECT_DESCRIPTOR => Primitive\ObjectDescriptor::class,
73
-        self::TYPE_REAL => Primitive\Real::class,
74
-        self::TYPE_ENUMERATED => Primitive\Enumerated::class,
75
-        self::TYPE_UTF8_STRING => Primitive\UTF8String::class,
76
-        self::TYPE_RELATIVE_OID => Primitive\RelativeOID::class,
77
-        self::TYPE_SEQUENCE => Constructed\Sequence::class,
78
-        self::TYPE_SET => Constructed\Set::class,
79
-        self::TYPE_NUMERIC_STRING => Primitive\NumericString::class,
80
-        self::TYPE_PRINTABLE_STRING => Primitive\PrintableString::class,
81
-        self::TYPE_T61_STRING => Primitive\T61String::class,
82
-        self::TYPE_VIDEOTEX_STRING => Primitive\VideotexString::class,
83
-        self::TYPE_IA5_STRING => Primitive\IA5String::class,
84
-        self::TYPE_UTC_TIME => Primitive\UTCTime::class,
85
-        self::TYPE_GENERALIZED_TIME => Primitive\GeneralizedTime::class,
86
-        self::TYPE_GRAPHIC_STRING => Primitive\GraphicString::class,
87
-        self::TYPE_VISIBLE_STRING => Primitive\VisibleString::class,
88
-        self::TYPE_GENERAL_STRING => Primitive\GeneralString::class,
89
-        self::TYPE_UNIVERSAL_STRING => Primitive\UniversalString::class,
90
-        self::TYPE_CHARACTER_STRING => Primitive\CharacterString::class,
91
-        self::TYPE_BMP_STRING => Primitive\BMPString::class,
92
-    ];
57
+	/**
58
+	 * Mapping from universal type tag to implementation class name.
59
+	 *
60
+	 * @internal
61
+	 *
62
+	 * @var array
63
+	 */
64
+	const MAP_TAG_TO_CLASS = [
65
+		self::TYPE_EOC => Primitive\EOC::class,
66
+		self::TYPE_BOOLEAN => Primitive\Boolean::class,
67
+		self::TYPE_INTEGER => Primitive\Integer::class,
68
+		self::TYPE_BIT_STRING => Primitive\BitString::class,
69
+		self::TYPE_OCTET_STRING => Primitive\OctetString::class,
70
+		self::TYPE_NULL => Primitive\NullType::class,
71
+		self::TYPE_OBJECT_IDENTIFIER => Primitive\ObjectIdentifier::class,
72
+		self::TYPE_OBJECT_DESCRIPTOR => Primitive\ObjectDescriptor::class,
73
+		self::TYPE_REAL => Primitive\Real::class,
74
+		self::TYPE_ENUMERATED => Primitive\Enumerated::class,
75
+		self::TYPE_UTF8_STRING => Primitive\UTF8String::class,
76
+		self::TYPE_RELATIVE_OID => Primitive\RelativeOID::class,
77
+		self::TYPE_SEQUENCE => Constructed\Sequence::class,
78
+		self::TYPE_SET => Constructed\Set::class,
79
+		self::TYPE_NUMERIC_STRING => Primitive\NumericString::class,
80
+		self::TYPE_PRINTABLE_STRING => Primitive\PrintableString::class,
81
+		self::TYPE_T61_STRING => Primitive\T61String::class,
82
+		self::TYPE_VIDEOTEX_STRING => Primitive\VideotexString::class,
83
+		self::TYPE_IA5_STRING => Primitive\IA5String::class,
84
+		self::TYPE_UTC_TIME => Primitive\UTCTime::class,
85
+		self::TYPE_GENERALIZED_TIME => Primitive\GeneralizedTime::class,
86
+		self::TYPE_GRAPHIC_STRING => Primitive\GraphicString::class,
87
+		self::TYPE_VISIBLE_STRING => Primitive\VisibleString::class,
88
+		self::TYPE_GENERAL_STRING => Primitive\GeneralString::class,
89
+		self::TYPE_UNIVERSAL_STRING => Primitive\UniversalString::class,
90
+		self::TYPE_CHARACTER_STRING => Primitive\CharacterString::class,
91
+		self::TYPE_BMP_STRING => Primitive\BMPString::class,
92
+	];
93 93
 
94
-    /**
95
-     * Pseudotype for all string types.
96
-     *
97
-     * May be used as an expectation parameter.
98
-     *
99
-     * @var int
100
-     */
101
-    const TYPE_STRING = -1;
94
+	/**
95
+	 * Pseudotype for all string types.
96
+	 *
97
+	 * May be used as an expectation parameter.
98
+	 *
99
+	 * @var int
100
+	 */
101
+	const TYPE_STRING = -1;
102 102
 
103
-    /**
104
-     * Pseudotype for all time types.
105
-     *
106
-     * May be used as an expectation parameter.
107
-     *
108
-     * @var int
109
-     */
110
-    const TYPE_TIME = -2;
103
+	/**
104
+	 * Pseudotype for all time types.
105
+	 *
106
+	 * May be used as an expectation parameter.
107
+	 *
108
+	 * @var int
109
+	 */
110
+	const TYPE_TIME = -2;
111 111
 
112
-    /**
113
-     * Mapping from universal type tag to human readable name.
114
-     *
115
-     * @internal
116
-     *
117
-     * @var array
118
-     */
119
-    const MAP_TYPE_TO_NAME = [
120
-        self::TYPE_EOC => 'EOC',
121
-        self::TYPE_BOOLEAN => 'BOOLEAN',
122
-        self::TYPE_INTEGER => 'INTEGER',
123
-        self::TYPE_BIT_STRING => 'BIT STRING',
124
-        self::TYPE_OCTET_STRING => 'OCTET STRING',
125
-        self::TYPE_NULL => 'NULL',
126
-        self::TYPE_OBJECT_IDENTIFIER => 'OBJECT IDENTIFIER',
127
-        self::TYPE_OBJECT_DESCRIPTOR => 'ObjectDescriptor',
128
-        self::TYPE_EXTERNAL => 'EXTERNAL',
129
-        self::TYPE_REAL => 'REAL',
130
-        self::TYPE_ENUMERATED => 'ENUMERATED',
131
-        self::TYPE_EMBEDDED_PDV => 'EMBEDDED PDV',
132
-        self::TYPE_UTF8_STRING => 'UTF8String',
133
-        self::TYPE_RELATIVE_OID => 'RELATIVE-OID',
134
-        self::TYPE_SEQUENCE => 'SEQUENCE',
135
-        self::TYPE_SET => 'SET',
136
-        self::TYPE_NUMERIC_STRING => 'NumericString',
137
-        self::TYPE_PRINTABLE_STRING => 'PrintableString',
138
-        self::TYPE_T61_STRING => 'T61String',
139
-        self::TYPE_VIDEOTEX_STRING => 'VideotexString',
140
-        self::TYPE_IA5_STRING => 'IA5String',
141
-        self::TYPE_UTC_TIME => 'UTCTime',
142
-        self::TYPE_GENERALIZED_TIME => 'GeneralizedTime',
143
-        self::TYPE_GRAPHIC_STRING => 'GraphicString',
144
-        self::TYPE_VISIBLE_STRING => 'VisibleString',
145
-        self::TYPE_GENERAL_STRING => 'GeneralString',
146
-        self::TYPE_UNIVERSAL_STRING => 'UniversalString',
147
-        self::TYPE_CHARACTER_STRING => 'CHARACTER STRING',
148
-        self::TYPE_BMP_STRING => 'BMPString',
149
-        self::TYPE_STRING => 'Any String',
150
-        self::TYPE_TIME => 'Any Time',
151
-    ];
112
+	/**
113
+	 * Mapping from universal type tag to human readable name.
114
+	 *
115
+	 * @internal
116
+	 *
117
+	 * @var array
118
+	 */
119
+	const MAP_TYPE_TO_NAME = [
120
+		self::TYPE_EOC => 'EOC',
121
+		self::TYPE_BOOLEAN => 'BOOLEAN',
122
+		self::TYPE_INTEGER => 'INTEGER',
123
+		self::TYPE_BIT_STRING => 'BIT STRING',
124
+		self::TYPE_OCTET_STRING => 'OCTET STRING',
125
+		self::TYPE_NULL => 'NULL',
126
+		self::TYPE_OBJECT_IDENTIFIER => 'OBJECT IDENTIFIER',
127
+		self::TYPE_OBJECT_DESCRIPTOR => 'ObjectDescriptor',
128
+		self::TYPE_EXTERNAL => 'EXTERNAL',
129
+		self::TYPE_REAL => 'REAL',
130
+		self::TYPE_ENUMERATED => 'ENUMERATED',
131
+		self::TYPE_EMBEDDED_PDV => 'EMBEDDED PDV',
132
+		self::TYPE_UTF8_STRING => 'UTF8String',
133
+		self::TYPE_RELATIVE_OID => 'RELATIVE-OID',
134
+		self::TYPE_SEQUENCE => 'SEQUENCE',
135
+		self::TYPE_SET => 'SET',
136
+		self::TYPE_NUMERIC_STRING => 'NumericString',
137
+		self::TYPE_PRINTABLE_STRING => 'PrintableString',
138
+		self::TYPE_T61_STRING => 'T61String',
139
+		self::TYPE_VIDEOTEX_STRING => 'VideotexString',
140
+		self::TYPE_IA5_STRING => 'IA5String',
141
+		self::TYPE_UTC_TIME => 'UTCTime',
142
+		self::TYPE_GENERALIZED_TIME => 'GeneralizedTime',
143
+		self::TYPE_GRAPHIC_STRING => 'GraphicString',
144
+		self::TYPE_VISIBLE_STRING => 'VisibleString',
145
+		self::TYPE_GENERAL_STRING => 'GeneralString',
146
+		self::TYPE_UNIVERSAL_STRING => 'UniversalString',
147
+		self::TYPE_CHARACTER_STRING => 'CHARACTER STRING',
148
+		self::TYPE_BMP_STRING => 'BMPString',
149
+		self::TYPE_STRING => 'Any String',
150
+		self::TYPE_TIME => 'Any Time',
151
+	];
152 152
 
153
-    /**
154
-     * Element's type tag.
155
-     *
156
-     * @var int
157
-     */
158
-    protected $_typeTag;
153
+	/**
154
+	 * Element's type tag.
155
+	 *
156
+	 * @var int
157
+	 */
158
+	protected $_typeTag;
159 159
 
160
-    /**
161
-     * Whether type shall be encoded with indefinite length.
162
-     *
163
-     * @var bool
164
-     */
165
-    protected $_indefiniteLength = false;
160
+	/**
161
+	 * Whether type shall be encoded with indefinite length.
162
+	 *
163
+	 * @var bool
164
+	 */
165
+	protected $_indefiniteLength = false;
166 166
 
167
-    /**
168
-     * {@inheritdoc}
169
-     */
170
-    abstract public function typeClass(): int;
167
+	/**
168
+	 * {@inheritdoc}
169
+	 */
170
+	abstract public function typeClass(): int;
171 171
 
172
-    /**
173
-     * {@inheritdoc}
174
-     */
175
-    abstract public function isConstructed(): bool;
172
+	/**
173
+	 * {@inheritdoc}
174
+	 */
175
+	abstract public function isConstructed(): bool;
176 176
 
177
-    /**
178
-     * Decode element from DER data.
179
-     *
180
-     * @param string   $data   DER encoded data
181
-     * @param null|int $offset Reference to the variable that contains offset
182
-     *                         into the data where to start parsing.
183
-     *                         Variable is updated to the offset next to the
184
-     *                         parsed element. If null, start from offset 0.
185
-     *
186
-     * @throws DecodeException           If decoding fails
187
-     * @throws \UnexpectedValueException If called in the context of an expected
188
-     *                                   type, but decoding yields another type
189
-     *
190
-     * @return ElementBase
191
-     */
192
-    public static function fromDER(string $data, int &$offset = null): ElementBase
193
-    {
194
-        $idx = $offset ?? 0;
195
-        // decode identifier
196
-        $identifier = Identifier::fromDER($data, $idx);
197
-        // determine class that implements type specific decoding
198
-        $cls = self::_determineImplClass($identifier);
199
-        try {
200
-            // decode remaining element
201
-            $element = $cls::_decodeFromDER($identifier, $data, $idx);
202
-        } catch (\LogicException $e) {
203
-            // rethrow as a RuntimeException for unified exception handling
204
-            throw new DecodeException(
205
-                sprintf('Error while decoding %s.',
206
-                    self::tagToName($identifier->intTag())), 0, $e);
207
-        }
208
-        // if called in the context of a concrete class, check
209
-        // that decoded type matches the type of a calling class
210
-        $called_class = get_called_class();
211
-        if (self::class != $called_class) {
212
-            if (!$element instanceof $called_class) {
213
-                throw new \UnexpectedValueException(
214
-                    sprintf('%s expected, got %s.', $called_class,
215
-                        get_class($element)));
216
-            }
217
-        }
218
-        // update offset for the caller
219
-        if (isset($offset)) {
220
-            $offset = $idx;
221
-        }
222
-        return $element;
223
-    }
177
+	/**
178
+	 * Decode element from DER data.
179
+	 *
180
+	 * @param string   $data   DER encoded data
181
+	 * @param null|int $offset Reference to the variable that contains offset
182
+	 *                         into the data where to start parsing.
183
+	 *                         Variable is updated to the offset next to the
184
+	 *                         parsed element. If null, start from offset 0.
185
+	 *
186
+	 * @throws DecodeException           If decoding fails
187
+	 * @throws \UnexpectedValueException If called in the context of an expected
188
+	 *                                   type, but decoding yields another type
189
+	 *
190
+	 * @return ElementBase
191
+	 */
192
+	public static function fromDER(string $data, int &$offset = null): ElementBase
193
+	{
194
+		$idx = $offset ?? 0;
195
+		// decode identifier
196
+		$identifier = Identifier::fromDER($data, $idx);
197
+		// determine class that implements type specific decoding
198
+		$cls = self::_determineImplClass($identifier);
199
+		try {
200
+			// decode remaining element
201
+			$element = $cls::_decodeFromDER($identifier, $data, $idx);
202
+		} catch (\LogicException $e) {
203
+			// rethrow as a RuntimeException for unified exception handling
204
+			throw new DecodeException(
205
+				sprintf('Error while decoding %s.',
206
+					self::tagToName($identifier->intTag())), 0, $e);
207
+		}
208
+		// if called in the context of a concrete class, check
209
+		// that decoded type matches the type of a calling class
210
+		$called_class = get_called_class();
211
+		if (self::class != $called_class) {
212
+			if (!$element instanceof $called_class) {
213
+				throw new \UnexpectedValueException(
214
+					sprintf('%s expected, got %s.', $called_class,
215
+						get_class($element)));
216
+			}
217
+		}
218
+		// update offset for the caller
219
+		if (isset($offset)) {
220
+			$offset = $idx;
221
+		}
222
+		return $element;
223
+	}
224 224
 
225
-    /**
226
-     * {@inheritdoc}
227
-     */
228
-    public function toDER(): string
229
-    {
230
-        $identifier = new Identifier($this->typeClass(),
231
-            $this->isConstructed() ? Identifier::CONSTRUCTED : Identifier::PRIMITIVE,
232
-            $this->_typeTag);
233
-        $content = $this->_encodedContentDER();
234
-        if ($this->_indefiniteLength) {
235
-            $length = new Length(0, true);
236
-            $eoc = new Primitive\EOC();
237
-            return $identifier->toDER() . $length->toDER() . $content .
238
-                $eoc->toDER();
239
-        }
240
-        $length = new Length(strlen($content));
241
-        return $identifier->toDER() . $length->toDER() . $content;
242
-    }
225
+	/**
226
+	 * {@inheritdoc}
227
+	 */
228
+	public function toDER(): string
229
+	{
230
+		$identifier = new Identifier($this->typeClass(),
231
+			$this->isConstructed() ? Identifier::CONSTRUCTED : Identifier::PRIMITIVE,
232
+			$this->_typeTag);
233
+		$content = $this->_encodedContentDER();
234
+		if ($this->_indefiniteLength) {
235
+			$length = new Length(0, true);
236
+			$eoc = new Primitive\EOC();
237
+			return $identifier->toDER() . $length->toDER() . $content .
238
+				$eoc->toDER();
239
+		}
240
+		$length = new Length(strlen($content));
241
+		return $identifier->toDER() . $length->toDER() . $content;
242
+	}
243 243
 
244
-    /**
245
-     * {@inheritdoc}
246
-     */
247
-    public function tag(): int
248
-    {
249
-        return $this->_typeTag;
250
-    }
244
+	/**
245
+	 * {@inheritdoc}
246
+	 */
247
+	public function tag(): int
248
+	{
249
+		return $this->_typeTag;
250
+	}
251 251
 
252
-    /**
253
-     * {@inheritdoc}
254
-     */
255
-    public function isType(int $tag): bool
256
-    {
257
-        // if element is context specific
258
-        if (Identifier::CLASS_CONTEXT_SPECIFIC === $this->typeClass()) {
259
-            return false;
260
-        }
261
-        // negative tags identify an abstract pseudotype
262
-        if ($tag < 0) {
263
-            return $this->_isPseudoType($tag);
264
-        }
265
-        return $this->_isConcreteType($tag);
266
-    }
252
+	/**
253
+	 * {@inheritdoc}
254
+	 */
255
+	public function isType(int $tag): bool
256
+	{
257
+		// if element is context specific
258
+		if (Identifier::CLASS_CONTEXT_SPECIFIC === $this->typeClass()) {
259
+			return false;
260
+		}
261
+		// negative tags identify an abstract pseudotype
262
+		if ($tag < 0) {
263
+			return $this->_isPseudoType($tag);
264
+		}
265
+		return $this->_isConcreteType($tag);
266
+	}
267 267
 
268
-    /**
269
-     * {@inheritdoc}
270
-     */
271
-    public function expectType(int $tag): ElementBase
272
-    {
273
-        if (!$this->isType($tag)) {
274
-            throw new \UnexpectedValueException(
275
-                sprintf('%s expected, got %s.', self::tagToName($tag),
276
-                    $this->_typeDescriptorString()));
277
-        }
278
-        return $this;
279
-    }
268
+	/**
269
+	 * {@inheritdoc}
270
+	 */
271
+	public function expectType(int $tag): ElementBase
272
+	{
273
+		if (!$this->isType($tag)) {
274
+			throw new \UnexpectedValueException(
275
+				sprintf('%s expected, got %s.', self::tagToName($tag),
276
+					$this->_typeDescriptorString()));
277
+		}
278
+		return $this;
279
+	}
280 280
 
281
-    /**
282
-     * {@inheritdoc}
283
-     */
284
-    public function isTagged(): bool
285
-    {
286
-        return $this instanceof TaggedType;
287
-    }
281
+	/**
282
+	 * {@inheritdoc}
283
+	 */
284
+	public function isTagged(): bool
285
+	{
286
+		return $this instanceof TaggedType;
287
+	}
288 288
 
289
-    /**
290
-     * {@inheritdoc}
291
-     */
292
-    public function expectTagged(?int $tag = null): TaggedType
293
-    {
294
-        if (!$this->isTagged()) {
295
-            throw new \UnexpectedValueException(
296
-                sprintf('Context specific element expected, got %s.',
297
-                    Identifier::classToName($this->typeClass())));
298
-        }
299
-        if (isset($tag) && $this->tag() !== $tag) {
300
-            throw new \UnexpectedValueException(
301
-                sprintf('Tag %d expected, got %d.', $tag, $this->tag()));
302
-        }
303
-        return $this;
304
-    }
289
+	/**
290
+	 * {@inheritdoc}
291
+	 */
292
+	public function expectTagged(?int $tag = null): TaggedType
293
+	{
294
+		if (!$this->isTagged()) {
295
+			throw new \UnexpectedValueException(
296
+				sprintf('Context specific element expected, got %s.',
297
+					Identifier::classToName($this->typeClass())));
298
+		}
299
+		if (isset($tag) && $this->tag() !== $tag) {
300
+			throw new \UnexpectedValueException(
301
+				sprintf('Tag %d expected, got %d.', $tag, $this->tag()));
302
+		}
303
+		return $this;
304
+	}
305 305
 
306
-    /**
307
-     * Whether element has indefinite length.
308
-     *
309
-     * @return bool
310
-     */
311
-    public function hasIndefiniteLength(): bool
312
-    {
313
-        return $this->_indefiniteLength;
314
-    }
306
+	/**
307
+	 * Whether element has indefinite length.
308
+	 *
309
+	 * @return bool
310
+	 */
311
+	public function hasIndefiniteLength(): bool
312
+	{
313
+		return $this->_indefiniteLength;
314
+	}
315 315
 
316
-    /**
317
-     * Get self with indefinite length encoding set.
318
-     *
319
-     * @param bool $indefinite True for indefinite length, false for definite
320
-     *                         length
321
-     *
322
-     * @return self
323
-     */
324
-    public function withIndefiniteLength(bool $indefinite = true): self
325
-    {
326
-        $obj = clone $this;
327
-        $obj->_indefiniteLength = $indefinite;
328
-        return $obj;
329
-    }
316
+	/**
317
+	 * Get self with indefinite length encoding set.
318
+	 *
319
+	 * @param bool $indefinite True for indefinite length, false for definite
320
+	 *                         length
321
+	 *
322
+	 * @return self
323
+	 */
324
+	public function withIndefiniteLength(bool $indefinite = true): self
325
+	{
326
+		$obj = clone $this;
327
+		$obj->_indefiniteLength = $indefinite;
328
+		return $obj;
329
+	}
330 330
 
331
-    /**
332
-     * {@inheritdoc}
333
-     */
334
-    final public function asElement(): Element
335
-    {
336
-        return $this;
337
-    }
331
+	/**
332
+	 * {@inheritdoc}
333
+	 */
334
+	final public function asElement(): Element
335
+	{
336
+		return $this;
337
+	}
338 338
 
339
-    /**
340
-     * Get element decorated with UnspecifiedType object.
341
-     *
342
-     * @return UnspecifiedType
343
-     */
344
-    public function asUnspecified(): UnspecifiedType
345
-    {
346
-        return new UnspecifiedType($this);
347
-    }
339
+	/**
340
+	 * Get element decorated with UnspecifiedType object.
341
+	 *
342
+	 * @return UnspecifiedType
343
+	 */
344
+	public function asUnspecified(): UnspecifiedType
345
+	{
346
+		return new UnspecifiedType($this);
347
+	}
348 348
 
349
-    /**
350
-     * Get human readable name for an universal tag.
351
-     *
352
-     * @param int $tag
353
-     *
354
-     * @return string
355
-     */
356
-    public static function tagToName(int $tag): string
357
-    {
358
-        if (!array_key_exists($tag, self::MAP_TYPE_TO_NAME)) {
359
-            return "TAG ${tag}";
360
-        }
361
-        return self::MAP_TYPE_TO_NAME[$tag];
362
-    }
349
+	/**
350
+	 * Get human readable name for an universal tag.
351
+	 *
352
+	 * @param int $tag
353
+	 *
354
+	 * @return string
355
+	 */
356
+	public static function tagToName(int $tag): string
357
+	{
358
+		if (!array_key_exists($tag, self::MAP_TYPE_TO_NAME)) {
359
+			return "TAG ${tag}";
360
+		}
361
+		return self::MAP_TYPE_TO_NAME[$tag];
362
+	}
363 363
 
364
-    /**
365
-     * Get the content encoded in DER.
366
-     *
367
-     * Returns the DER encoded content without identifier and length header
368
-     * octets.
369
-     *
370
-     * @return string
371
-     */
372
-    abstract protected function _encodedContentDER(): string;
364
+	/**
365
+	 * Get the content encoded in DER.
366
+	 *
367
+	 * Returns the DER encoded content without identifier and length header
368
+	 * octets.
369
+	 *
370
+	 * @return string
371
+	 */
372
+	abstract protected function _encodedContentDER(): string;
373 373
 
374
-    /**
375
-     * Decode type-specific element from DER.
376
-     *
377
-     * @param Identifier $identifier Pre-parsed identifier
378
-     * @param string     $data       DER data
379
-     * @param int        $offset     Offset in data to the next byte after identifier
380
-     *
381
-     * @throws DecodeException If decoding fails
382
-     *
383
-     * @return ElementBase
384
-     */
385
-    protected static function _decodeFromDER(Identifier $identifier,
386
-        string $data, int &$offset): ElementBase
387
-    {
388
-        throw new \BadMethodCallException(
389
-            __METHOD__ . ' must be implemented in derived class.');
390
-    }
374
+	/**
375
+	 * Decode type-specific element from DER.
376
+	 *
377
+	 * @param Identifier $identifier Pre-parsed identifier
378
+	 * @param string     $data       DER data
379
+	 * @param int        $offset     Offset in data to the next byte after identifier
380
+	 *
381
+	 * @throws DecodeException If decoding fails
382
+	 *
383
+	 * @return ElementBase
384
+	 */
385
+	protected static function _decodeFromDER(Identifier $identifier,
386
+		string $data, int &$offset): ElementBase
387
+	{
388
+		throw new \BadMethodCallException(
389
+			__METHOD__ . ' must be implemented in derived class.');
390
+	}
391 391
 
392
-    /**
393
-     * Determine the class that implements the type.
394
-     *
395
-     * @param Identifier $identifier
396
-     *
397
-     * @return string Class name
398
-     */
399
-    protected static function _determineImplClass(Identifier $identifier): string
400
-    {
401
-        switch ($identifier->typeClass()) {
402
-            case Identifier::CLASS_UNIVERSAL:
403
-                return self::_determineUniversalImplClass($identifier->intTag());
404
-            case Identifier::CLASS_CONTEXT_SPECIFIC:
405
-                return ContextSpecificType::class;
406
-            case Identifier::CLASS_APPLICATION:
407
-                return ApplicationType::class;
408
-            case Identifier::CLASS_PRIVATE:
409
-                return PrivateType::class;
410
-        }
411
-        throw new \UnexpectedValueException(
412
-            sprintf('%s %d not implemented.',
413
-                Identifier::classToName($identifier->typeClass()),
414
-                $identifier->tag()));
415
-    }
392
+	/**
393
+	 * Determine the class that implements the type.
394
+	 *
395
+	 * @param Identifier $identifier
396
+	 *
397
+	 * @return string Class name
398
+	 */
399
+	protected static function _determineImplClass(Identifier $identifier): string
400
+	{
401
+		switch ($identifier->typeClass()) {
402
+			case Identifier::CLASS_UNIVERSAL:
403
+				return self::_determineUniversalImplClass($identifier->intTag());
404
+			case Identifier::CLASS_CONTEXT_SPECIFIC:
405
+				return ContextSpecificType::class;
406
+			case Identifier::CLASS_APPLICATION:
407
+				return ApplicationType::class;
408
+			case Identifier::CLASS_PRIVATE:
409
+				return PrivateType::class;
410
+		}
411
+		throw new \UnexpectedValueException(
412
+			sprintf('%s %d not implemented.',
413
+				Identifier::classToName($identifier->typeClass()),
414
+				$identifier->tag()));
415
+	}
416 416
 
417
-    /**
418
-     * Determine the class that implements an universal type of the given tag.
419
-     *
420
-     * @param int $tag
421
-     *
422
-     * @throws \UnexpectedValueException
423
-     *
424
-     * @return string Class name
425
-     */
426
-    protected static function _determineUniversalImplClass(int $tag): string
427
-    {
428
-        if (!array_key_exists($tag, self::MAP_TAG_TO_CLASS)) {
429
-            throw new \UnexpectedValueException(
430
-                "Universal tag ${tag} not implemented.");
431
-        }
432
-        return self::MAP_TAG_TO_CLASS[$tag];
433
-    }
417
+	/**
418
+	 * Determine the class that implements an universal type of the given tag.
419
+	 *
420
+	 * @param int $tag
421
+	 *
422
+	 * @throws \UnexpectedValueException
423
+	 *
424
+	 * @return string Class name
425
+	 */
426
+	protected static function _determineUniversalImplClass(int $tag): string
427
+	{
428
+		if (!array_key_exists($tag, self::MAP_TAG_TO_CLASS)) {
429
+			throw new \UnexpectedValueException(
430
+				"Universal tag ${tag} not implemented.");
431
+		}
432
+		return self::MAP_TAG_TO_CLASS[$tag];
433
+	}
434 434
 
435
-    /**
436
-     * Get textual description of the type for debugging purposes.
437
-     *
438
-     * @return string
439
-     */
440
-    protected function _typeDescriptorString(): string
441
-    {
442
-        if (Identifier::CLASS_UNIVERSAL == $this->typeClass()) {
443
-            return self::tagToName($this->_typeTag);
444
-        }
445
-        return sprintf('%s TAG %d', Identifier::classToName($this->typeClass()),
446
-            $this->_typeTag);
447
-    }
435
+	/**
436
+	 * Get textual description of the type for debugging purposes.
437
+	 *
438
+	 * @return string
439
+	 */
440
+	protected function _typeDescriptorString(): string
441
+	{
442
+		if (Identifier::CLASS_UNIVERSAL == $this->typeClass()) {
443
+			return self::tagToName($this->_typeTag);
444
+		}
445
+		return sprintf('%s TAG %d', Identifier::classToName($this->typeClass()),
446
+			$this->_typeTag);
447
+	}
448 448
 
449
-    /**
450
-     * Check whether the element is a concrete type of a given tag.
451
-     *
452
-     * @param int $tag
453
-     *
454
-     * @return bool
455
-     */
456
-    private function _isConcreteType(int $tag): bool
457
-    {
458
-        // if tag doesn't match
459
-        if ($this->tag() != $tag) {
460
-            return false;
461
-        }
462
-        // if type is universal check that instance is of a correct class
463
-        if (Identifier::CLASS_UNIVERSAL == $this->typeClass()) {
464
-            $cls = self::_determineUniversalImplClass($tag);
465
-            if (!$this instanceof $cls) {
466
-                return false;
467
-            }
468
-        }
469
-        return true;
470
-    }
449
+	/**
450
+	 * Check whether the element is a concrete type of a given tag.
451
+	 *
452
+	 * @param int $tag
453
+	 *
454
+	 * @return bool
455
+	 */
456
+	private function _isConcreteType(int $tag): bool
457
+	{
458
+		// if tag doesn't match
459
+		if ($this->tag() != $tag) {
460
+			return false;
461
+		}
462
+		// if type is universal check that instance is of a correct class
463
+		if (Identifier::CLASS_UNIVERSAL == $this->typeClass()) {
464
+			$cls = self::_determineUniversalImplClass($tag);
465
+			if (!$this instanceof $cls) {
466
+				return false;
467
+			}
468
+		}
469
+		return true;
470
+	}
471 471
 
472
-    /**
473
-     * Check whether the element is a pseudotype.
474
-     *
475
-     * @param int $tag
476
-     *
477
-     * @return bool
478
-     */
479
-    private function _isPseudoType(int $tag): bool
480
-    {
481
-        switch ($tag) {
482
-            case self::TYPE_STRING:
483
-                return $this instanceof StringType;
484
-            case self::TYPE_TIME:
485
-                return $this instanceof TimeType;
486
-        }
487
-        return false;
488
-    }
472
+	/**
473
+	 * Check whether the element is a pseudotype.
474
+	 *
475
+	 * @param int $tag
476
+	 *
477
+	 * @return bool
478
+	 */
479
+	private function _isPseudoType(int $tag): bool
480
+	{
481
+		switch ($tag) {
482
+			case self::TYPE_STRING:
483
+				return $this instanceof StringType;
484
+			case self::TYPE_TIME:
485
+				return $this instanceof TimeType;
486
+		}
487
+		return false;
488
+	}
489 489
 }
Please login to merge, or discard this patch.
Switch Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -399,14 +399,14 @@  discard block
 block discarded – undo
399 399
     protected static function _determineImplClass(Identifier $identifier): string
400 400
     {
401 401
         switch ($identifier->typeClass()) {
402
-            case Identifier::CLASS_UNIVERSAL:
403
-                return self::_determineUniversalImplClass($identifier->intTag());
404
-            case Identifier::CLASS_CONTEXT_SPECIFIC:
405
-                return ContextSpecificType::class;
406
-            case Identifier::CLASS_APPLICATION:
407
-                return ApplicationType::class;
408
-            case Identifier::CLASS_PRIVATE:
409
-                return PrivateType::class;
402
+        case Identifier::CLASS_UNIVERSAL:
403
+            return self::_determineUniversalImplClass($identifier->intTag());
404
+        case Identifier::CLASS_CONTEXT_SPECIFIC:
405
+            return ContextSpecificType::class;
406
+        case Identifier::CLASS_APPLICATION:
407
+            return ApplicationType::class;
408
+        case Identifier::CLASS_PRIVATE:
409
+            return PrivateType::class;
410 410
         }
411 411
         throw new \UnexpectedValueException(
412 412
             sprintf('%s %d not implemented.',
@@ -479,10 +479,10 @@  discard block
 block discarded – undo
479 479
     private function _isPseudoType(int $tag): bool
480 480
     {
481 481
         switch ($tag) {
482
-            case self::TYPE_STRING:
483
-                return $this instanceof StringType;
484
-            case self::TYPE_TIME:
485
-                return $this instanceof TimeType;
482
+        case self::TYPE_STRING:
483
+            return $this instanceof StringType;
484
+        case self::TYPE_TIME:
485
+            return $this instanceof TimeType;
486 486
         }
487 487
         return false;
488 488
     }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\ASN1;
6 6
 
Please login to merge, or discard this patch.
lib/ASN1/Type/Constructed/Sequence.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\ASN1\Type\Constructed;
6 6
 
Please login to merge, or discard this patch.
lib/ASN1/Type/Constructed/Set.php 2 patches
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -12,56 +12,56 @@
 block discarded – undo
12 12
  */
13 13
 class Set extends Structure
14 14
 {
15
-    /**
16
-     * Constructor.
17
-     *
18
-     * @param Element ...$elements Any number of elements
19
-     */
20
-    public function __construct(Element ...$elements)
21
-    {
22
-        $this->_typeTag = self::TYPE_SET;
23
-        parent::__construct(...$elements);
24
-    }
15
+	/**
16
+	 * Constructor.
17
+	 *
18
+	 * @param Element ...$elements Any number of elements
19
+	 */
20
+	public function __construct(Element ...$elements)
21
+	{
22
+		$this->_typeTag = self::TYPE_SET;
23
+		parent::__construct(...$elements);
24
+	}
25 25
 
26
-    /**
27
-     * Sort by canonical ascending order.
28
-     * 
29
-     * Used for DER encoding of SET type.
30
-     *
31
-     * @return self
32
-     */
33
-    public function sortedSet(): self
34
-    {
35
-        $obj = clone $this;
36
-        usort($obj->_elements,
37
-            function (Element $a, Element $b) {
38
-                if ($a->typeClass() != $b->typeClass()) {
39
-                    return $a->typeClass() < $b->typeClass() ? -1 : 1;
40
-                }
41
-                if ($a->tag() == $b->tag()) {
42
-                    return 0;
43
-                }
44
-                return $a->tag() < $b->tag() ? -1 : 1;
45
-            });
46
-        return $obj;
47
-    }
26
+	/**
27
+	 * Sort by canonical ascending order.
28
+	 * 
29
+	 * Used for DER encoding of SET type.
30
+	 *
31
+	 * @return self
32
+	 */
33
+	public function sortedSet(): self
34
+	{
35
+		$obj = clone $this;
36
+		usort($obj->_elements,
37
+			function (Element $a, Element $b) {
38
+				if ($a->typeClass() != $b->typeClass()) {
39
+					return $a->typeClass() < $b->typeClass() ? -1 : 1;
40
+				}
41
+				if ($a->tag() == $b->tag()) {
42
+					return 0;
43
+				}
44
+				return $a->tag() < $b->tag() ? -1 : 1;
45
+			});
46
+		return $obj;
47
+	}
48 48
 
49
-    /**
50
-     * Sort by encoding ascending order.
51
-     * 
52
-     * Used for DER encoding of SET OF type.
53
-     *
54
-     * @return self
55
-     */
56
-    public function sortedSetOf(): self
57
-    {
58
-        $obj = clone $this;
59
-        usort($obj->_elements,
60
-            function (Element $a, Element $b) {
61
-                $a_der = $a->toDER();
62
-                $b_der = $b->toDER();
63
-                return strcmp($a_der, $b_der);
64
-            });
65
-        return $obj;
66
-    }
49
+	/**
50
+	 * Sort by encoding ascending order.
51
+	 * 
52
+	 * Used for DER encoding of SET OF type.
53
+	 *
54
+	 * @return self
55
+	 */
56
+	public function sortedSetOf(): self
57
+	{
58
+		$obj = clone $this;
59
+		usort($obj->_elements,
60
+			function (Element $a, Element $b) {
61
+				$a_der = $a->toDER();
62
+				$b_der = $b->toDER();
63
+				return strcmp($a_der, $b_der);
64
+			});
65
+		return $obj;
66
+	}
67 67
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\ASN1\Type\Constructed;
6 6
 
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
     {
35 35
         $obj = clone $this;
36 36
         usort($obj->_elements,
37
-            function (Element $a, Element $b) {
37
+            function(Element $a, Element $b) {
38 38
                 if ($a->typeClass() != $b->typeClass()) {
39 39
                     return $a->typeClass() < $b->typeClass() ? -1 : 1;
40 40
                 }
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
     {
58 58
         $obj = clone $this;
59 59
         usort($obj->_elements,
60
-            function (Element $a, Element $b) {
60
+            function(Element $a, Element $b) {
61 61
                 $a_der = $a->toDER();
62 62
                 $b_der = $b->toDER();
63 63
                 return strcmp($a_der, $b_der);
Please login to merge, or discard this patch.
lib/ASN1/Type/UniversalClass.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -11,13 +11,13 @@
 block discarded – undo
11 11
  */
12 12
 trait UniversalClass
13 13
 {
14
-    /**
15
-     * @see \Sop\ASN1\Feature\ElementBase::typeClass()
16
-     *
17
-     * @return int
18
-     */
19
-    public function typeClass(): int
20
-    {
21
-        return Identifier::CLASS_UNIVERSAL;
22
-    }
14
+	/**
15
+	 * @see \Sop\ASN1\Feature\ElementBase::typeClass()
16
+	 *
17
+	 * @return int
18
+	 */
19
+	public function typeClass(): int
20
+	{
21
+		return Identifier::CLASS_UNIVERSAL;
22
+	}
23 23
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\ASN1\Type;
6 6
 
Please login to merge, or discard this patch.
lib/ASN1/Type/PrimitiveString.php 2 patches
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -14,36 +14,36 @@
 block discarded – undo
14 14
  */
15 15
 abstract class PrimitiveString extends StringType
16 16
 {
17
-    use PrimitiveType;
17
+	use PrimitiveType;
18 18
 
19
-    /**
20
-     * {@inheritdoc}
21
-     */
22
-    protected function _encodedContentDER(): string
23
-    {
24
-        return $this->_string;
25
-    }
19
+	/**
20
+	 * {@inheritdoc}
21
+	 */
22
+	protected function _encodedContentDER(): string
23
+	{
24
+		return $this->_string;
25
+	}
26 26
 
27
-    /**
28
-     * {@inheritdoc}
29
-     */
30
-    protected static function _decodeFromDER(Identifier $identifier,
31
-        string $data, int &$offset): ElementBase
32
-    {
33
-        $idx = $offset;
34
-        if (!$identifier->isPrimitive()) {
35
-            throw new DecodeException('DER encoded string must be primitive.');
36
-        }
37
-        $length = Length::expectFromDER($data, $idx)->intLength();
38
-        $str = $length ? substr($data, $idx, $length) : '';
39
-        // substr should never return false, since length is
40
-        // checked by Length::expectFromDER.
41
-        assert(is_string($str), new DecodeException('substr'));
42
-        $offset = $idx + $length;
43
-        try {
44
-            return new static($str);
45
-        } catch (\InvalidArgumentException $e) {
46
-            throw new DecodeException($e->getMessage(), 0, $e);
47
-        }
48
-    }
27
+	/**
28
+	 * {@inheritdoc}
29
+	 */
30
+	protected static function _decodeFromDER(Identifier $identifier,
31
+		string $data, int &$offset): ElementBase
32
+	{
33
+		$idx = $offset;
34
+		if (!$identifier->isPrimitive()) {
35
+			throw new DecodeException('DER encoded string must be primitive.');
36
+		}
37
+		$length = Length::expectFromDER($data, $idx)->intLength();
38
+		$str = $length ? substr($data, $idx, $length) : '';
39
+		// substr should never return false, since length is
40
+		// checked by Length::expectFromDER.
41
+		assert(is_string($str), new DecodeException('substr'));
42
+		$offset = $idx + $length;
43
+		try {
44
+			return new static($str);
45
+		} catch (\InvalidArgumentException $e) {
46
+			throw new DecodeException($e->getMessage(), 0, $e);
47
+		}
48
+	}
49 49
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\ASN1\Type;
6 6
 
Please login to merge, or discard this patch.
lib/ASN1/Type/Structure.php 2 patches
Indentation   +389 added lines, -389 removed lines patch added patch discarded remove patch
@@ -15,416 +15,416 @@
 block discarded – undo
15 15
  */
16 16
 abstract class Structure extends Element implements \Countable, \IteratorAggregate
17 17
 {
18
-    use UniversalClass;
18
+	use UniversalClass;
19 19
 
20
-    /**
21
-     * Array of elements in the structure.
22
-     *
23
-     * @var Element[]
24
-     */
25
-    protected $_elements;
20
+	/**
21
+	 * Array of elements in the structure.
22
+	 *
23
+	 * @var Element[]
24
+	 */
25
+	protected $_elements;
26 26
 
27
-    /**
28
-     * Lookup table for the tagged elements.
29
-     *
30
-     * @var null|TaggedType[]
31
-     */
32
-    private $_taggedMap;
27
+	/**
28
+	 * Lookup table for the tagged elements.
29
+	 *
30
+	 * @var null|TaggedType[]
31
+	 */
32
+	private $_taggedMap;
33 33
 
34
-    /**
35
-     * Cache variable of elements wrapped into UnspecifiedType objects.
36
-     *
37
-     * @var null|UnspecifiedType[]
38
-     */
39
-    private $_unspecifiedTypes;
34
+	/**
35
+	 * Cache variable of elements wrapped into UnspecifiedType objects.
36
+	 *
37
+	 * @var null|UnspecifiedType[]
38
+	 */
39
+	private $_unspecifiedTypes;
40 40
 
41
-    /**
42
-     * Constructor.
43
-     *
44
-     * @param ElementBase ...$elements Any number of elements
45
-     */
46
-    public function __construct(ElementBase ...$elements)
47
-    {
48
-        $this->_elements = array_map(
49
-            function (ElementBase $el) {
50
-                return $el->asElement();
51
-            }, $elements);
52
-    }
41
+	/**
42
+	 * Constructor.
43
+	 *
44
+	 * @param ElementBase ...$elements Any number of elements
45
+	 */
46
+	public function __construct(ElementBase ...$elements)
47
+	{
48
+		$this->_elements = array_map(
49
+			function (ElementBase $el) {
50
+				return $el->asElement();
51
+			}, $elements);
52
+	}
53 53
 
54
-    /**
55
-     * Clone magic method.
56
-     */
57
-    public function __clone()
58
-    {
59
-        // clear cache-variables
60
-        $this->_taggedMap = null;
61
-        $this->_unspecifiedTypes = null;
62
-    }
54
+	/**
55
+	 * Clone magic method.
56
+	 */
57
+	public function __clone()
58
+	{
59
+		// clear cache-variables
60
+		$this->_taggedMap = null;
61
+		$this->_unspecifiedTypes = null;
62
+	}
63 63
 
64
-    /**
65
-     * {@inheritdoc}
66
-     */
67
-    public function isConstructed(): bool
68
-    {
69
-        return true;
70
-    }
64
+	/**
65
+	 * {@inheritdoc}
66
+	 */
67
+	public function isConstructed(): bool
68
+	{
69
+		return true;
70
+	}
71 71
 
72
-    /**
73
-     * Explode DER structure to DER encoded components that it contains.
74
-     *
75
-     * @param string $data
76
-     *
77
-     * @throws DecodeException
78
-     *
79
-     * @return string[]
80
-     */
81
-    public static function explodeDER(string $data): array
82
-    {
83
-        $offset = 0;
84
-        $identifier = Identifier::fromDER($data, $offset);
85
-        if (!$identifier->isConstructed()) {
86
-            throw new DecodeException('Element is not constructed.');
87
-        }
88
-        $length = Length::expectFromDER($data, $offset);
89
-        if ($length->isIndefinite()) {
90
-            throw new DecodeException(
91
-                'Explode not implemented for indefinite length encoding.');
92
-        }
93
-        $end = $offset + $length->intLength();
94
-        $parts = [];
95
-        while ($offset < $end) {
96
-            // start of the element
97
-            $idx = $offset;
98
-            // skip identifier
99
-            Identifier::fromDER($data, $offset);
100
-            // decode element length
101
-            $length = Length::expectFromDER($data, $offset)->intLength();
102
-            // extract der encoding of the element
103
-            $parts[] = substr($data, $idx, $offset - $idx + $length);
104
-            // update offset over content
105
-            $offset += $length;
106
-        }
107
-        return $parts;
108
-    }
72
+	/**
73
+	 * Explode DER structure to DER encoded components that it contains.
74
+	 *
75
+	 * @param string $data
76
+	 *
77
+	 * @throws DecodeException
78
+	 *
79
+	 * @return string[]
80
+	 */
81
+	public static function explodeDER(string $data): array
82
+	{
83
+		$offset = 0;
84
+		$identifier = Identifier::fromDER($data, $offset);
85
+		if (!$identifier->isConstructed()) {
86
+			throw new DecodeException('Element is not constructed.');
87
+		}
88
+		$length = Length::expectFromDER($data, $offset);
89
+		if ($length->isIndefinite()) {
90
+			throw new DecodeException(
91
+				'Explode not implemented for indefinite length encoding.');
92
+		}
93
+		$end = $offset + $length->intLength();
94
+		$parts = [];
95
+		while ($offset < $end) {
96
+			// start of the element
97
+			$idx = $offset;
98
+			// skip identifier
99
+			Identifier::fromDER($data, $offset);
100
+			// decode element length
101
+			$length = Length::expectFromDER($data, $offset)->intLength();
102
+			// extract der encoding of the element
103
+			$parts[] = substr($data, $idx, $offset - $idx + $length);
104
+			// update offset over content
105
+			$offset += $length;
106
+		}
107
+		return $parts;
108
+	}
109 109
 
110
-    /**
111
-     * Get self with an element at the given index replaced by another.
112
-     *
113
-     * @param int     $idx Element index
114
-     * @param Element $el  New element to insert into the structure
115
-     *
116
-     * @throws \OutOfBoundsException
117
-     *
118
-     * @return self
119
-     */
120
-    public function withReplaced(int $idx, Element $el): self
121
-    {
122
-        if (!isset($this->_elements[$idx])) {
123
-            throw new \OutOfBoundsException(
124
-                "Structure doesn't have element at index ${idx}.");
125
-        }
126
-        $obj = clone $this;
127
-        $obj->_elements[$idx] = $el;
128
-        return $obj;
129
-    }
110
+	/**
111
+	 * Get self with an element at the given index replaced by another.
112
+	 *
113
+	 * @param int     $idx Element index
114
+	 * @param Element $el  New element to insert into the structure
115
+	 *
116
+	 * @throws \OutOfBoundsException
117
+	 *
118
+	 * @return self
119
+	 */
120
+	public function withReplaced(int $idx, Element $el): self
121
+	{
122
+		if (!isset($this->_elements[$idx])) {
123
+			throw new \OutOfBoundsException(
124
+				"Structure doesn't have element at index ${idx}.");
125
+		}
126
+		$obj = clone $this;
127
+		$obj->_elements[$idx] = $el;
128
+		return $obj;
129
+	}
130 130
 
131
-    /**
132
-     * Get self with an element inserted before the given index.
133
-     *
134
-     * @param int     $idx Element index
135
-     * @param Element $el  New element to insert into the structure
136
-     *
137
-     * @throws \OutOfBoundsException
138
-     *
139
-     * @return self
140
-     */
141
-    public function withInserted(int $idx, Element $el): self
142
-    {
143
-        if (count($this->_elements) < $idx || $idx < 0) {
144
-            throw new \OutOfBoundsException("Index ${idx} is out of bounds.");
145
-        }
146
-        $obj = clone $this;
147
-        array_splice($obj->_elements, $idx, 0, [$el]);
148
-        return $obj;
149
-    }
131
+	/**
132
+	 * Get self with an element inserted before the given index.
133
+	 *
134
+	 * @param int     $idx Element index
135
+	 * @param Element $el  New element to insert into the structure
136
+	 *
137
+	 * @throws \OutOfBoundsException
138
+	 *
139
+	 * @return self
140
+	 */
141
+	public function withInserted(int $idx, Element $el): self
142
+	{
143
+		if (count($this->_elements) < $idx || $idx < 0) {
144
+			throw new \OutOfBoundsException("Index ${idx} is out of bounds.");
145
+		}
146
+		$obj = clone $this;
147
+		array_splice($obj->_elements, $idx, 0, [$el]);
148
+		return $obj;
149
+	}
150 150
 
151
-    /**
152
-     * Get self with an element appended to the end.
153
-     *
154
-     * @param Element $el Element to insert into the structure
155
-     *
156
-     * @return self
157
-     */
158
-    public function withAppended(Element $el): self
159
-    {
160
-        $obj = clone $this;
161
-        array_push($obj->_elements, $el);
162
-        return $obj;
163
-    }
151
+	/**
152
+	 * Get self with an element appended to the end.
153
+	 *
154
+	 * @param Element $el Element to insert into the structure
155
+	 *
156
+	 * @return self
157
+	 */
158
+	public function withAppended(Element $el): self
159
+	{
160
+		$obj = clone $this;
161
+		array_push($obj->_elements, $el);
162
+		return $obj;
163
+	}
164 164
 
165
-    /**
166
-     * Get self with an element prepended in the beginning.
167
-     *
168
-     * @param Element $el Element to insert into the structure
169
-     *
170
-     * @return self
171
-     */
172
-    public function withPrepended(Element $el): self
173
-    {
174
-        $obj = clone $this;
175
-        array_unshift($obj->_elements, $el);
176
-        return $obj;
177
-    }
165
+	/**
166
+	 * Get self with an element prepended in the beginning.
167
+	 *
168
+	 * @param Element $el Element to insert into the structure
169
+	 *
170
+	 * @return self
171
+	 */
172
+	public function withPrepended(Element $el): self
173
+	{
174
+		$obj = clone $this;
175
+		array_unshift($obj->_elements, $el);
176
+		return $obj;
177
+	}
178 178
 
179
-    /**
180
-     * Get self with an element at the given index removed.
181
-     *
182
-     * @param int $idx Element index
183
-     *
184
-     * @throws \OutOfBoundsException
185
-     *
186
-     * @return self
187
-     */
188
-    public function withoutElement(int $idx): self
189
-    {
190
-        if (!isset($this->_elements[$idx])) {
191
-            throw new \OutOfBoundsException(
192
-                "Structure doesn't have element at index ${idx}.");
193
-        }
194
-        $obj = clone $this;
195
-        array_splice($obj->_elements, $idx, 1);
196
-        return $obj;
197
-    }
179
+	/**
180
+	 * Get self with an element at the given index removed.
181
+	 *
182
+	 * @param int $idx Element index
183
+	 *
184
+	 * @throws \OutOfBoundsException
185
+	 *
186
+	 * @return self
187
+	 */
188
+	public function withoutElement(int $idx): self
189
+	{
190
+		if (!isset($this->_elements[$idx])) {
191
+			throw new \OutOfBoundsException(
192
+				"Structure doesn't have element at index ${idx}.");
193
+		}
194
+		$obj = clone $this;
195
+		array_splice($obj->_elements, $idx, 1);
196
+		return $obj;
197
+	}
198 198
 
199
-    /**
200
-     * Get elements in the structure.
201
-     *
202
-     * @return UnspecifiedType[]
203
-     */
204
-    public function elements(): array
205
-    {
206
-        if (!isset($this->_unspecifiedTypes)) {
207
-            $this->_unspecifiedTypes = array_map(
208
-                function (Element $el) {
209
-                    return new UnspecifiedType($el);
210
-                }, $this->_elements);
211
-        }
212
-        return $this->_unspecifiedTypes;
213
-    }
199
+	/**
200
+	 * Get elements in the structure.
201
+	 *
202
+	 * @return UnspecifiedType[]
203
+	 */
204
+	public function elements(): array
205
+	{
206
+		if (!isset($this->_unspecifiedTypes)) {
207
+			$this->_unspecifiedTypes = array_map(
208
+				function (Element $el) {
209
+					return new UnspecifiedType($el);
210
+				}, $this->_elements);
211
+		}
212
+		return $this->_unspecifiedTypes;
213
+	}
214 214
 
215
-    /**
216
-     * Check whether the structure has an element at the given index, optionally
217
-     * satisfying given tag expectation.
218
-     *
219
-     * @param int      $idx         Index 0..n
220
-     * @param null|int $expectedTag Optional type tag expectation
221
-     *
222
-     * @return bool
223
-     */
224
-    public function has(int $idx, ?int $expectedTag = null): bool
225
-    {
226
-        if (!isset($this->_elements[$idx])) {
227
-            return false;
228
-        }
229
-        if (isset($expectedTag)) {
230
-            if (!$this->_elements[$idx]->isType($expectedTag)) {
231
-                return false;
232
-            }
233
-        }
234
-        return true;
235
-    }
215
+	/**
216
+	 * Check whether the structure has an element at the given index, optionally
217
+	 * satisfying given tag expectation.
218
+	 *
219
+	 * @param int      $idx         Index 0..n
220
+	 * @param null|int $expectedTag Optional type tag expectation
221
+	 *
222
+	 * @return bool
223
+	 */
224
+	public function has(int $idx, ?int $expectedTag = null): bool
225
+	{
226
+		if (!isset($this->_elements[$idx])) {
227
+			return false;
228
+		}
229
+		if (isset($expectedTag)) {
230
+			if (!$this->_elements[$idx]->isType($expectedTag)) {
231
+				return false;
232
+			}
233
+		}
234
+		return true;
235
+	}
236 236
 
237
-    /**
238
-     * Get the element at the given index, optionally checking that the element
239
-     * has a given tag.
240
-     *
241
-     * <strong>NOTE!</strong> Expectation checking is deprecated and should be
242
-     * done with <code>UnspecifiedType</code>.
243
-     *
244
-     * @todo Remove
245
-     *
246
-     * @param int      $idx         Index 0..n
247
-     * @param null|int $expectedTag Optional type tag expectation
248
-     *
249
-     * @throws \OutOfBoundsException     If element doesn't exists
250
-     * @throws \UnexpectedValueException If expectation fails
251
-     *
252
-     * @return UnspecifiedType
253
-     */
254
-    public function at(int $idx, ?int $expectedTag = null): UnspecifiedType
255
-    {
256
-        if (!isset($this->_elements[$idx])) {
257
-            throw new \OutOfBoundsException(
258
-                "Structure doesn't have an element at index ${idx}.");
259
-        }
260
-        $element = $this->_elements[$idx];
261
-        if (isset($expectedTag)) {
262
-            $element->expectType($expectedTag);
263
-        }
264
-        return new UnspecifiedType($element);
265
-    }
237
+	/**
238
+	 * Get the element at the given index, optionally checking that the element
239
+	 * has a given tag.
240
+	 *
241
+	 * <strong>NOTE!</strong> Expectation checking is deprecated and should be
242
+	 * done with <code>UnspecifiedType</code>.
243
+	 *
244
+	 * @todo Remove
245
+	 *
246
+	 * @param int      $idx         Index 0..n
247
+	 * @param null|int $expectedTag Optional type tag expectation
248
+	 *
249
+	 * @throws \OutOfBoundsException     If element doesn't exists
250
+	 * @throws \UnexpectedValueException If expectation fails
251
+	 *
252
+	 * @return UnspecifiedType
253
+	 */
254
+	public function at(int $idx, ?int $expectedTag = null): UnspecifiedType
255
+	{
256
+		if (!isset($this->_elements[$idx])) {
257
+			throw new \OutOfBoundsException(
258
+				"Structure doesn't have an element at index ${idx}.");
259
+		}
260
+		$element = $this->_elements[$idx];
261
+		if (isset($expectedTag)) {
262
+			$element->expectType($expectedTag);
263
+		}
264
+		return new UnspecifiedType($element);
265
+	}
266 266
 
267
-    /**
268
-     * Check whether the structure contains a context specific element with a
269
-     * given tag.
270
-     *
271
-     * @param int $tag Tag number
272
-     *
273
-     * @return bool
274
-     */
275
-    public function hasTagged(int $tag): bool
276
-    {
277
-        // lazily build lookup map
278
-        if (!isset($this->_taggedMap)) {
279
-            $this->_taggedMap = [];
280
-            foreach ($this->_elements as $element) {
281
-                if ($element->isTagged()) {
282
-                    $this->_taggedMap[$element->tag()] = $element;
283
-                }
284
-            }
285
-        }
286
-        return isset($this->_taggedMap[$tag]);
287
-    }
267
+	/**
268
+	 * Check whether the structure contains a context specific element with a
269
+	 * given tag.
270
+	 *
271
+	 * @param int $tag Tag number
272
+	 *
273
+	 * @return bool
274
+	 */
275
+	public function hasTagged(int $tag): bool
276
+	{
277
+		// lazily build lookup map
278
+		if (!isset($this->_taggedMap)) {
279
+			$this->_taggedMap = [];
280
+			foreach ($this->_elements as $element) {
281
+				if ($element->isTagged()) {
282
+					$this->_taggedMap[$element->tag()] = $element;
283
+				}
284
+			}
285
+		}
286
+		return isset($this->_taggedMap[$tag]);
287
+	}
288 288
 
289
-    /**
290
-     * Get a context specific element tagged with a given tag.
291
-     *
292
-     * @param int $tag
293
-     *
294
-     * @throws \LogicException If tag doesn't exists
295
-     *
296
-     * @return TaggedType
297
-     */
298
-    public function getTagged(int $tag): TaggedType
299
-    {
300
-        if (!$this->hasTagged($tag)) {
301
-            throw new \LogicException("No tagged element for tag ${tag}.");
302
-        }
303
-        return $this->_taggedMap[$tag];
304
-    }
289
+	/**
290
+	 * Get a context specific element tagged with a given tag.
291
+	 *
292
+	 * @param int $tag
293
+	 *
294
+	 * @throws \LogicException If tag doesn't exists
295
+	 *
296
+	 * @return TaggedType
297
+	 */
298
+	public function getTagged(int $tag): TaggedType
299
+	{
300
+		if (!$this->hasTagged($tag)) {
301
+			throw new \LogicException("No tagged element for tag ${tag}.");
302
+		}
303
+		return $this->_taggedMap[$tag];
304
+	}
305 305
 
306
-    /**
307
-     * @see \Countable::count()
308
-     *
309
-     * @return int
310
-     */
311
-    public function count(): int
312
-    {
313
-        return count($this->_elements);
314
-    }
306
+	/**
307
+	 * @see \Countable::count()
308
+	 *
309
+	 * @return int
310
+	 */
311
+	public function count(): int
312
+	{
313
+		return count($this->_elements);
314
+	}
315 315
 
316
-    /**
317
-     * Get an iterator for the UnspecifiedElement objects.
318
-     *
319
-     * @see \IteratorAggregate::getIterator()
320
-     *
321
-     * @return \ArrayIterator
322
-     */
323
-    public function getIterator(): \ArrayIterator
324
-    {
325
-        return new \ArrayIterator($this->elements());
326
-    }
316
+	/**
317
+	 * Get an iterator for the UnspecifiedElement objects.
318
+	 *
319
+	 * @see \IteratorAggregate::getIterator()
320
+	 *
321
+	 * @return \ArrayIterator
322
+	 */
323
+	public function getIterator(): \ArrayIterator
324
+	{
325
+		return new \ArrayIterator($this->elements());
326
+	}
327 327
 
328
-    /**
329
-     * @see \Sop\ASN1\Element::_encodedContentDER()
330
-     *
331
-     * @return string
332
-     */
333
-    protected function _encodedContentDER(): string
334
-    {
335
-        $data = '';
336
-        foreach ($this->_elements as $element) {
337
-            $data .= $element->toDER();
338
-        }
339
-        return $data;
340
-    }
328
+	/**
329
+	 * @see \Sop\ASN1\Element::_encodedContentDER()
330
+	 *
331
+	 * @return string
332
+	 */
333
+	protected function _encodedContentDER(): string
334
+	{
335
+		$data = '';
336
+		foreach ($this->_elements as $element) {
337
+			$data .= $element->toDER();
338
+		}
339
+		return $data;
340
+	}
341 341
 
342
-    /**
343
-     * {@inheritdoc}
344
-     *
345
-     * @see \Sop\ASN1\Element::_decodeFromDER()
346
-     *
347
-     * @return self
348
-     */
349
-    protected static function _decodeFromDER(Identifier $identifier,
350
-        string $data, int &$offset): ElementBase
351
-    {
352
-        if (!$identifier->isConstructed()) {
353
-            throw new DecodeException(
354
-                'Structured element must have constructed bit set.');
355
-        }
356
-        $idx = $offset;
357
-        $length = Length::expectFromDER($data, $idx);
358
-        if ($length->isIndefinite()) {
359
-            $type = self::_decodeIndefiniteLength($data, $idx);
360
-        } else {
361
-            $type = self::_decodeDefiniteLength($data, $idx,
362
-                $length->intLength());
363
-        }
364
-        $offset = $idx;
365
-        return $type;
366
-    }
342
+	/**
343
+	 * {@inheritdoc}
344
+	 *
345
+	 * @see \Sop\ASN1\Element::_decodeFromDER()
346
+	 *
347
+	 * @return self
348
+	 */
349
+	protected static function _decodeFromDER(Identifier $identifier,
350
+		string $data, int &$offset): ElementBase
351
+	{
352
+		if (!$identifier->isConstructed()) {
353
+			throw new DecodeException(
354
+				'Structured element must have constructed bit set.');
355
+		}
356
+		$idx = $offset;
357
+		$length = Length::expectFromDER($data, $idx);
358
+		if ($length->isIndefinite()) {
359
+			$type = self::_decodeIndefiniteLength($data, $idx);
360
+		} else {
361
+			$type = self::_decodeDefiniteLength($data, $idx,
362
+				$length->intLength());
363
+		}
364
+		$offset = $idx;
365
+		return $type;
366
+	}
367 367
 
368
-    /**
369
-     * Decode elements for a definite length.
370
-     *
371
-     * @param string $data   DER data
372
-     * @param int    $offset Offset to data
373
-     * @param int    $length Number of bytes to decode
374
-     *
375
-     * @throws DecodeException
376
-     *
377
-     * @return ElementBase
378
-     */
379
-    private static function _decodeDefiniteLength(string $data, int &$offset,
380
-        int $length): ElementBase
381
-    {
382
-        $idx = $offset;
383
-        $end = $idx + $length;
384
-        $elements = [];
385
-        while ($idx < $end) {
386
-            $elements[] = Element::fromDER($data, $idx);
387
-            // check that element didn't overflow length
388
-            if ($idx > $end) {
389
-                throw new DecodeException(
390
-                    "Structure's content overflows length.");
391
-            }
392
-        }
393
-        $offset = $idx;
394
-        // return instance by static late binding
395
-        return new static(...$elements);
396
-    }
368
+	/**
369
+	 * Decode elements for a definite length.
370
+	 *
371
+	 * @param string $data   DER data
372
+	 * @param int    $offset Offset to data
373
+	 * @param int    $length Number of bytes to decode
374
+	 *
375
+	 * @throws DecodeException
376
+	 *
377
+	 * @return ElementBase
378
+	 */
379
+	private static function _decodeDefiniteLength(string $data, int &$offset,
380
+		int $length): ElementBase
381
+	{
382
+		$idx = $offset;
383
+		$end = $idx + $length;
384
+		$elements = [];
385
+		while ($idx < $end) {
386
+			$elements[] = Element::fromDER($data, $idx);
387
+			// check that element didn't overflow length
388
+			if ($idx > $end) {
389
+				throw new DecodeException(
390
+					"Structure's content overflows length.");
391
+			}
392
+		}
393
+		$offset = $idx;
394
+		// return instance by static late binding
395
+		return new static(...$elements);
396
+	}
397 397
 
398
-    /**
399
-     * Decode elements for an indefinite length.
400
-     *
401
-     * @param string $data   DER data
402
-     * @param int    $offset Offset to data
403
-     *
404
-     * @throws DecodeException
405
-     *
406
-     * @return ElementBase
407
-     */
408
-    private static function _decodeIndefiniteLength(
409
-        string $data, int &$offset): ElementBase
410
-    {
411
-        $idx = $offset;
412
-        $elements = [];
413
-        $end = strlen($data);
414
-        while (true) {
415
-            if ($idx >= $end) {
416
-                throw new DecodeException(
417
-                    'Unexpected end of data while decoding indefinite length structure.');
418
-            }
419
-            $el = Element::fromDER($data, $idx);
420
-            if ($el->isType(self::TYPE_EOC)) {
421
-                break;
422
-            }
423
-            $elements[] = $el;
424
-        }
425
-        $offset = $idx;
426
-        $type = new static(...$elements);
427
-        $type->_indefiniteLength = true;
428
-        return $type;
429
-    }
398
+	/**
399
+	 * Decode elements for an indefinite length.
400
+	 *
401
+	 * @param string $data   DER data
402
+	 * @param int    $offset Offset to data
403
+	 *
404
+	 * @throws DecodeException
405
+	 *
406
+	 * @return ElementBase
407
+	 */
408
+	private static function _decodeIndefiniteLength(
409
+		string $data, int &$offset): ElementBase
410
+	{
411
+		$idx = $offset;
412
+		$elements = [];
413
+		$end = strlen($data);
414
+		while (true) {
415
+			if ($idx >= $end) {
416
+				throw new DecodeException(
417
+					'Unexpected end of data while decoding indefinite length structure.');
418
+			}
419
+			$el = Element::fromDER($data, $idx);
420
+			if ($el->isType(self::TYPE_EOC)) {
421
+				break;
422
+			}
423
+			$elements[] = $el;
424
+		}
425
+		$offset = $idx;
426
+		$type = new static(...$elements);
427
+		$type->_indefiniteLength = true;
428
+		return $type;
429
+	}
430 430
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\ASN1\Type;
6 6
 
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
     public function __construct(ElementBase ...$elements)
47 47
     {
48 48
         $this->_elements = array_map(
49
-            function (ElementBase $el) {
49
+            function(ElementBase $el) {
50 50
                 return $el->asElement();
51 51
             }, $elements);
52 52
     }
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
     {
206 206
         if (!isset($this->_unspecifiedTypes)) {
207 207
             $this->_unspecifiedTypes = array_map(
208
-                function (Element $el) {
208
+                function(Element $el) {
209 209
                     return new UnspecifiedType($el);
210 210
                 }, $this->_elements);
211 211
         }
Please login to merge, or discard this patch.
lib/ASN1/Type/TimeType.php 2 patches
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -11,93 +11,93 @@
 block discarded – undo
11 11
  */
12 12
 abstract class TimeType extends Element
13 13
 {
14
-    /**
15
-     * UTC timezone.
16
-     *
17
-     * @var string
18
-     */
19
-    const TZ_UTC = 'UTC';
14
+	/**
15
+	 * UTC timezone.
16
+	 *
17
+	 * @var string
18
+	 */
19
+	const TZ_UTC = 'UTC';
20 20
 
21
-    /**
22
-     * Date and time.
23
-     *
24
-     * @var \DateTimeImmutable
25
-     */
26
-    protected $_dateTime;
21
+	/**
22
+	 * Date and time.
23
+	 *
24
+	 * @var \DateTimeImmutable
25
+	 */
26
+	protected $_dateTime;
27 27
 
28
-    /**
29
-     * Constructor.
30
-     *
31
-     * @param \DateTimeImmutable $dt
32
-     */
33
-    public function __construct(\DateTimeImmutable $dt)
34
-    {
35
-        $this->_dateTime = $dt;
36
-    }
28
+	/**
29
+	 * Constructor.
30
+	 *
31
+	 * @param \DateTimeImmutable $dt
32
+	 */
33
+	public function __construct(\DateTimeImmutable $dt)
34
+	{
35
+		$this->_dateTime = $dt;
36
+	}
37 37
 
38
-    /**
39
-     * Initialize from datetime string.
40
-     *
41
-     * @see http://php.net/manual/en/datetime.formats.php
42
-     *
43
-     * @param string      $time Time string
44
-     * @param null|string $tz   timezone, if null use default
45
-     *
46
-     * @throws \RuntimeException
47
-     *
48
-     * @return self
49
-     */
50
-    public static function fromString(string $time, ?string $tz = null): self
51
-    {
52
-        try {
53
-            if (!isset($tz)) {
54
-                $tz = date_default_timezone_get();
55
-            }
56
-            return new static(
57
-                new \DateTimeImmutable($time, self::_createTimeZone($tz)));
58
-        } catch (\Exception $e) {
59
-            throw new \RuntimeException(
60
-                'Failed to create DateTime: ' .
61
-                self::_getLastDateTimeImmutableErrorsStr(), 0, $e);
62
-        }
63
-    }
38
+	/**
39
+	 * Initialize from datetime string.
40
+	 *
41
+	 * @see http://php.net/manual/en/datetime.formats.php
42
+	 *
43
+	 * @param string      $time Time string
44
+	 * @param null|string $tz   timezone, if null use default
45
+	 *
46
+	 * @throws \RuntimeException
47
+	 *
48
+	 * @return self
49
+	 */
50
+	public static function fromString(string $time, ?string $tz = null): self
51
+	{
52
+		try {
53
+			if (!isset($tz)) {
54
+				$tz = date_default_timezone_get();
55
+			}
56
+			return new static(
57
+				new \DateTimeImmutable($time, self::_createTimeZone($tz)));
58
+		} catch (\Exception $e) {
59
+			throw new \RuntimeException(
60
+				'Failed to create DateTime: ' .
61
+				self::_getLastDateTimeImmutableErrorsStr(), 0, $e);
62
+		}
63
+	}
64 64
 
65
-    /**
66
-     * Get the date and time.
67
-     *
68
-     * @return \DateTimeImmutable
69
-     */
70
-    public function dateTime(): \DateTimeImmutable
71
-    {
72
-        return $this->_dateTime;
73
-    }
65
+	/**
66
+	 * Get the date and time.
67
+	 *
68
+	 * @return \DateTimeImmutable
69
+	 */
70
+	public function dateTime(): \DateTimeImmutable
71
+	{
72
+		return $this->_dateTime;
73
+	}
74 74
 
75
-    /**
76
-     * Create DateTimeZone object from string.
77
-     *
78
-     * @param string $tz
79
-     *
80
-     * @throws \UnexpectedValueException If timezone is invalid
81
-     *
82
-     * @return \DateTimeZone
83
-     */
84
-    protected static function _createTimeZone(string $tz): \DateTimeZone
85
-    {
86
-        try {
87
-            return new \DateTimeZone($tz);
88
-        } catch (\Exception $e) {
89
-            throw new \UnexpectedValueException('Invalid timezone.', 0, $e);
90
-        }
91
-    }
75
+	/**
76
+	 * Create DateTimeZone object from string.
77
+	 *
78
+	 * @param string $tz
79
+	 *
80
+	 * @throws \UnexpectedValueException If timezone is invalid
81
+	 *
82
+	 * @return \DateTimeZone
83
+	 */
84
+	protected static function _createTimeZone(string $tz): \DateTimeZone
85
+	{
86
+		try {
87
+			return new \DateTimeZone($tz);
88
+		} catch (\Exception $e) {
89
+			throw new \UnexpectedValueException('Invalid timezone.', 0, $e);
90
+		}
91
+	}
92 92
 
93
-    /**
94
-     * Get last error caused by DateTimeImmutable.
95
-     *
96
-     * @return string
97
-     */
98
-    protected static function _getLastDateTimeImmutableErrorsStr(): string
99
-    {
100
-        $errors = \DateTimeImmutable::getLastErrors()['errors'];
101
-        return implode(', ', $errors);
102
-    }
93
+	/**
94
+	 * Get last error caused by DateTimeImmutable.
95
+	 *
96
+	 * @return string
97
+	 */
98
+	protected static function _getLastDateTimeImmutableErrorsStr(): string
99
+	{
100
+		$errors = \DateTimeImmutable::getLastErrors()['errors'];
101
+		return implode(', ', $errors);
102
+	}
103 103
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\ASN1\Type;
6 6
 
Please login to merge, or discard this patch.
lib/ASN1/Type/Tagged/ApplicationType.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\ASN1\Type\Tagged;
6 6
 
Please login to merge, or discard this patch.
lib/ASN1/Type/Tagged/PrivateType.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Sop\ASN1\Type\Tagged;
6 6
 
Please login to merge, or discard this patch.