GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 58ee59...2e5bb5 )
by Joni
03:56
created

UnspecifiedType::asNull()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 7
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 2
1
<?php
2
3
namespace ASN1\Type;
4
5
use ASN1\Component\Identifier;
6
use ASN1\Element;
7
use ASN1\Feature\ElementBase;
8
use ASN1\Type\Constructed\Sequence;
9
use ASN1\Type\Constructed\Set;
10
use ASN1\Type\Primitive\BitString;
11
use ASN1\Type\Primitive\BMPString;
12
use ASN1\Type\Primitive\Boolean;
13
use ASN1\Type\Primitive\CharacterString;
14
use ASN1\Type\Primitive\Enumerated;
15
use ASN1\Type\Primitive\GeneralizedTime;
16
use ASN1\Type\Primitive\GeneralString;
17
use ASN1\Type\Primitive\GraphicString;
18
use ASN1\Type\Primitive\IA5String;
19
use ASN1\Type\Primitive\Integer;
20
use ASN1\Type\Primitive\NullType;
21
use ASN1\Type\Primitive\NumericString;
22
use ASN1\Type\Primitive\ObjectDescriptor;
23
use ASN1\Type\Primitive\ObjectIdentifier;
24
use ASN1\Type\Primitive\OctetString;
25
use ASN1\Type\Primitive\PrintableString;
26
use ASN1\Type\Primitive\Real;
27
use ASN1\Type\Primitive\RelativeOID;
28
use ASN1\Type\Primitive\T61String;
29
use ASN1\Type\Primitive\UniversalString;
30
use ASN1\Type\Primitive\UTCTime;
31
use ASN1\Type\Primitive\UTF8String;
32
use ASN1\Type\Primitive\VideotexString;
33
use ASN1\Type\Primitive\VisibleString;
34
use ASN1\Type\StringType;
35
use ASN1\Type\TaggedType;
36
use ASN1\Type\TimeType;
37
38
39
/**
40
 * Decorator class to wrap an element without already knowing the specific
41
 * underlying type.
42
 *
43
 * Provides accessor methods to test the underlying type and return a type
44
 * hinted instance of the concrete element.
45
 */
46
class UnspecifiedType implements ElementBase
47
{
48
	/**
49
	 * Wrapped element.
50
	 *
51
	 * @var Element
52
	 */
53
	private $_element;
54
	
55
	/**
56
	 * Constructor
57
	 *
58
	 * @param Element $el
59
	 */
60 85
	public function __construct(Element $el) {
61 85
		$this->_element = $el;
62 85
	}
63
	
64
	/**
65
	 * Compatibility method to dispatch calls to wrapped element.
66
	 *
67
	 * @deprecated Use <code>as*</code> accessor methods to ensure strict type
68
	 * @param string $mtd Method name
69
	 * @param array $args Arguments
70
	 * @return mixed
71
	 */
72
	public function __call($mtd, array $args) {
73
		return call_user_func_array([$this->_element, $mtd], $args);
74
	}
75
	
76
	/**
77
	 * Get the wrapped element as an abstract type.
78
	 *
79
	 * @return ElementBase
80
	 */
81 1
	public function asElement() {
82 1
		return $this->_element;
83
	}
84
	
85
	/**
86
	 * Get the wrapped element as a context specific tagged type.
87
	 *
88
	 * @throws \UnexpectedValueException
89
	 * @return TaggedType
90
	 */
91 2
	public function asTagged() {
92 2
		if (!$this->_element instanceof TaggedType) {
93 1
			throw new \UnexpectedValueException(
94 1
				"Tagged element expected, got " . $this->_typeDescriptorString());
95
		}
96 1
		return $this->_element;
97
	}
98
	
99
	/**
100
	 * Get the wrapped element as a boolean type.
101
	 *
102
	 * @throws \UnexpectedValueException
103
	 * @return Boolean
104
	 */
105 4 View Code Duplication
	public function asBoolean() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
106 4
		if (!$this->_element instanceof Boolean) {
107 1
			throw new \UnexpectedValueException(
108 1
				$this->_generateExceptionMessage(Element::TYPE_BOOLEAN));
109
		}
110 3
		return $this->_element;
111
	}
112
	
113
	/**
114
	 * Get the wrapped element as an integer type.
115
	 *
116
	 * @throws \UnexpectedValueException
117
	 * @return Integer
118
	 */
119 2 View Code Duplication
	public function asInteger() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
120 2
		if (!$this->_element instanceof Integer) {
121 1
			throw new \UnexpectedValueException(
122 1
				$this->_generateExceptionMessage(Element::TYPE_INTEGER));
123
		}
124 1
		return $this->_element;
125
	}
126
	
127
	/**
128
	 * Get the wrapped element as a bit string type.
129
	 *
130
	 * @throws \UnexpectedValueException
131
	 * @return BitString
132
	 */
133 2 View Code Duplication
	public function asBitString() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
134 2
		if (!$this->_element instanceof BitString) {
135 1
			throw new \UnexpectedValueException(
136 1
				$this->_generateExceptionMessage(Element::TYPE_BIT_STRING));
137
		}
138 1
		return $this->_element;
139
	}
140
	
141
	/**
142
	 * Get the wrapped element as an octet string type.
143
	 *
144
	 * @throws \UnexpectedValueException
145
	 * @return OctetString
146
	 */
147 2 View Code Duplication
	public function asOctetString() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
148 2
		if (!$this->_element instanceof OctetString) {
149 1
			throw new \UnexpectedValueException(
150 1
				$this->_generateExceptionMessage(Element::TYPE_OCTET_STRING));
151
		}
152 1
		return $this->_element;
153
	}
154
	
155
	/**
156
	 * Get the wrapped element as a null type.
157
	 *
158
	 * @throws \UnexpectedValueException
159
	 * @return NullType
160
	 */
161 7 View Code Duplication
	public function asNull() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
162 7
		if (!$this->_element instanceof NullType) {
163 2
			throw new \UnexpectedValueException(
164 2
				$this->_generateExceptionMessage(Element::TYPE_NULL));
165
		}
166 5
		return $this->_element;
167
	}
168
	
169
	/**
170
	 * Get the wrapped element as an object identifier type.
171
	 *
172
	 * @throws \UnexpectedValueException
173
	 * @return ObjectIdentifier
174
	 */
175 2 View Code Duplication
	public function asObjectIdentifier() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
176 2
		if (!$this->_element instanceof ObjectIdentifier) {
177 1
			throw new \UnexpectedValueException(
178 1
				$this->_generateExceptionMessage(
179 1
					Element::TYPE_OBJECT_IDENTIFIER));
180
		}
181 1
		return $this->_element;
182
	}
183
	
184
	/**
185
	 * Get the wrapped element as an object descriptor type.
186
	 *
187
	 * @throws \UnexpectedValueException
188
	 * @return ObjectDescriptor
189
	 */
190 2 View Code Duplication
	public function asObjectDescriptor() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
191 2
		if (!$this->_element instanceof ObjectDescriptor) {
192 1
			throw new \UnexpectedValueException(
193 1
				$this->_generateExceptionMessage(
194 1
					Element::TYPE_OBJECT_DESCRIPTOR));
195
		}
196 1
		return $this->_element;
197
	}
198
	
199
	/**
200
	 * Get the wrapped element as a real type.
201
	 *
202
	 * @throws \UnexpectedValueException
203
	 * @return Real
204
	 */
205 2 View Code Duplication
	public function asReal() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
206 2
		if (!$this->_element instanceof Real) {
207 1
			throw new \UnexpectedValueException(
208 1
				$this->_generateExceptionMessage(Element::TYPE_REAL));
209
		}
210 1
		return $this->_element;
211
	}
212
	
213
	/**
214
	 * Get the wrapped element as an enumerated type.
215
	 *
216
	 * @throws \UnexpectedValueException
217
	 * @return Enumerated
218
	 */
219 2 View Code Duplication
	public function asEnumerated() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
220 2
		if (!$this->_element instanceof Enumerated) {
221 1
			throw new \UnexpectedValueException(
222 1
				$this->_generateExceptionMessage(Element::TYPE_ENUMERATED));
223
		}
224 1
		return $this->_element;
225
	}
226
	
227
	/**
228
	 * Get the wrapped element as a UTF8 string type.
229
	 *
230
	 * @throws \UnexpectedValueException
231
	 * @return UTF8String
232
	 */
233 2 View Code Duplication
	public function asUTF8String() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
234 2
		if (!$this->_element instanceof UTF8String) {
235 1
			throw new \UnexpectedValueException(
236 1
				$this->_generateExceptionMessage(Element::TYPE_UTF8_STRING));
237
		}
238 1
		return $this->_element;
239
	}
240
	
241
	/**
242
	 * Get the wrapped element as a relative OID type.
243
	 *
244
	 * @throws \UnexpectedValueException
245
	 * @return RelativeOID
246
	 */
247 2 View Code Duplication
	public function asRelativeOID() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
248 2
		if (!$this->_element instanceof RelativeOID) {
249 1
			throw new \UnexpectedValueException(
250 1
				$this->_generateExceptionMessage(Element::TYPE_RELATIVE_OID));
251
		}
252 1
		return $this->_element;
253
	}
254
	
255
	/**
256
	 * Get the wrapped element as a sequence type.
257
	 *
258
	 * @throws \UnexpectedValueException
259
	 * @return Sequence
260
	 */
261 2 View Code Duplication
	public function asSequence() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
262 2
		if (!$this->_element instanceof Sequence) {
263 1
			throw new \UnexpectedValueException(
264 1
				$this->_generateExceptionMessage(Element::TYPE_SEQUENCE));
265
		}
266 1
		return $this->_element;
267
	}
268
	
269
	/**
270
	 * Get the wrapped element as a set type.
271
	 *
272
	 * @throws \UnexpectedValueException
273
	 * @return Set
274
	 */
275 2 View Code Duplication
	public function asSet() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
276 2
		if (!$this->_element instanceof Set) {
277 1
			throw new \UnexpectedValueException(
278 1
				$this->_generateExceptionMessage(Element::TYPE_SET));
279
		}
280 1
		return $this->_element;
281
	}
282
	
283
	/**
284
	 * Get the wrapped element as a numeric string type.
285
	 *
286
	 * @throws \UnexpectedValueException
287
	 * @return NumericString
288
	 */
289 2 View Code Duplication
	public function asNumericString() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
290 2
		if (!$this->_element instanceof NumericString) {
291 1
			throw new \UnexpectedValueException(
292 1
				$this->_generateExceptionMessage(Element::TYPE_NUMERIC_STRING));
293
		}
294 1
		return $this->_element;
295
	}
296
	
297
	/**
298
	 * Get the wrapped element as a printable string type.
299
	 *
300
	 * @throws \UnexpectedValueException
301
	 * @return PrintableString
302
	 */
303 2 View Code Duplication
	public function asPrintableString() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
304 2
		if (!$this->_element instanceof PrintableString) {
305 1
			throw new \UnexpectedValueException(
306 1
				$this->_generateExceptionMessage(Element::TYPE_PRINTABLE_STRING));
307
		}
308 1
		return $this->_element;
309
	}
310
	
311
	/**
312
	 * Get the wrapped element as a T61 string type.
313
	 *
314
	 * @throws \UnexpectedValueException
315
	 * @return T61String
316
	 */
317 2 View Code Duplication
	public function asT61String() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
318 2
		if (!$this->_element instanceof T61String) {
319 1
			throw new \UnexpectedValueException(
320 1
				$this->_generateExceptionMessage(Element::TYPE_T61_STRING));
321
		}
322 1
		return $this->_element;
323
	}
324
	
325
	/**
326
	 * Get the wrapped element as a videotex string type.
327
	 *
328
	 * @throws \UnexpectedValueException
329
	 * @return VideotexString
330
	 */
331 2 View Code Duplication
	public function asVideotexString() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
332 2
		if (!$this->_element instanceof VideotexString) {
333 1
			throw new \UnexpectedValueException(
334 1
				$this->_generateExceptionMessage(Element::TYPE_VIDEOTEX_STRING));
335
		}
336 1
		return $this->_element;
337
	}
338
	
339
	/**
340
	 * Get the wrapped element as a IA6 string type.
341
	 *
342
	 * @throws \UnexpectedValueException
343
	 * @return IA5String
344
	 */
345 2 View Code Duplication
	public function asIA5String() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
346 2
		if (!$this->_element instanceof IA5String) {
347 1
			throw new \UnexpectedValueException(
348 1
				$this->_generateExceptionMessage(Element::TYPE_IA5_STRING));
349
		}
350 1
		return $this->_element;
351
	}
352
	
353
	/**
354
	 * Get the wrapped element as an UTC time type.
355
	 *
356
	 * @throws \UnexpectedValueException
357
	 * @return UTCTime
358
	 */
359 2 View Code Duplication
	public function asUTCTime() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
360 2
		if (!$this->_element instanceof UTCTime) {
361 1
			throw new \UnexpectedValueException(
362 1
				$this->_generateExceptionMessage(Element::TYPE_UTC_TIME));
363
		}
364 1
		return $this->_element;
365
	}
366
	
367
	/**
368
	 * Get the wrapped element as a generalized time type.
369
	 *
370
	 * @throws \UnexpectedValueException
371
	 * @return GeneralizedTime
372
	 */
373 2 View Code Duplication
	public function asGeneralizedTime() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
374 2
		if (!$this->_element instanceof GeneralizedTime) {
375 1
			throw new \UnexpectedValueException(
376 1
				$this->_generateExceptionMessage(Element::TYPE_GENERALIZED_TIME));
377
		}
378 1
		return $this->_element;
379
	}
380
	
381
	/**
382
	 * Get the wrapped element as a graphic string type.
383
	 *
384
	 * @throws \UnexpectedValueException
385
	 * @return GraphicString
386
	 */
387 2 View Code Duplication
	public function asGraphicString() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
388 2
		if (!$this->_element instanceof GraphicString) {
389 1
			throw new \UnexpectedValueException(
390 1
				$this->_generateExceptionMessage(Element::TYPE_GRAPHIC_STRING));
391
		}
392 1
		return $this->_element;
393
	}
394
	
395
	/**
396
	 * Get the wrapped element as a visible string type.
397
	 *
398
	 * @throws \UnexpectedValueException
399
	 * @return VisibleString
400
	 */
401 2 View Code Duplication
	public function asVisibleString() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
402 2
		if (!$this->_element instanceof VisibleString) {
403 1
			throw new \UnexpectedValueException(
404 1
				$this->_generateExceptionMessage(Element::TYPE_VISIBLE_STRING));
405
		}
406 1
		return $this->_element;
407
	}
408
	
409
	/**
410
	 * Get the wrapped element as a general string type.
411
	 *
412
	 * @throws \UnexpectedValueException
413
	 * @return GeneralString
414
	 */
415 2 View Code Duplication
	public function asGeneralString() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
416 2
		if (!$this->_element instanceof GeneralString) {
417 1
			throw new \UnexpectedValueException(
418 1
				$this->_generateExceptionMessage(Element::TYPE_GENERAL_STRING));
419
		}
420 1
		return $this->_element;
421
	}
422
	
423
	/**
424
	 * Get the wrapped element as a universal string type.
425
	 *
426
	 * @throws \UnexpectedValueException
427
	 * @return UniversalString
428
	 */
429 2 View Code Duplication
	public function asUniversalString() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
430 2
		if (!$this->_element instanceof UniversalString) {
431 1
			throw new \UnexpectedValueException(
432 1
				$this->_generateExceptionMessage(Element::TYPE_UNIVERSAL_STRING));
433
		}
434 1
		return $this->_element;
435
	}
436
	
437
	/**
438
	 * Get the wrapped element as a character string type.
439
	 *
440
	 * @throws \UnexpectedValueException
441
	 * @return CharacterString
442
	 */
443 2 View Code Duplication
	public function asCharacterString() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
444 2
		if (!$this->_element instanceof CharacterString) {
445 1
			throw new \UnexpectedValueException(
446 1
				$this->_generateExceptionMessage(Element::TYPE_CHARACTER_STRING));
447
		}
448 1
		return $this->_element;
449
	}
450
	
451
	/**
452
	 * Get the wrapped element as a BMP string type.
453
	 *
454
	 * @throws \UnexpectedValueException
455
	 * @return BMPString
456
	 */
457 2 View Code Duplication
	public function asBMPString() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
458 2
		if (!$this->_element instanceof BMPString) {
459 1
			throw new \UnexpectedValueException(
460 1
				$this->_generateExceptionMessage(Element::TYPE_BMP_STRING));
461
		}
462 1
		return $this->_element;
463
	}
464
	
465
	/**
466
	 * Get the wrapped element as any string type.
467
	 *
468
	 * @throws \UnexpectedValueException
469
	 * @return StringType
470
	 */
471 2 View Code Duplication
	public function asString() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
472 2
		if (!$this->_element instanceof StringType) {
473 1
			throw new \UnexpectedValueException(
474 1
				$this->_generateExceptionMessage(Element::TYPE_STRING));
475
		}
476 1
		return $this->_element;
477
	}
478
	
479
	/**
480
	 * Get the wrapped element as any time type.
481
	 *
482
	 * @throws \UnexpectedValueException
483
	 * @return TimeType
484
	 */
485 2 View Code Duplication
	public function asTime() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
486 2
		if (!$this->_element instanceof TimeType) {
487 1
			throw new \UnexpectedValueException(
488 1
				$this->_generateExceptionMessage(Element::TYPE_TIME));
489
		}
490 1
		return $this->_element;
491
	}
492
	
493
	/**
494
	 * Generate message for exceptions thrown by <code>as*</code> methods.
495
	 *
496
	 * @param int $tag Type tag of the expected element
497
	 * @return string
498
	 */
499 29
	private function _generateExceptionMessage($tag) {
500 29
		return Element::tagToName($tag) . " expected, got " .
501 29
			 $this->_typeDescriptorString() . ".";
502
	}
503
	
504
	/**
505
	 * Get textual description of the wrapped element for debugging purposes.
506
	 *
507
	 * @return string
508
	 */
509 30
	private function _typeDescriptorString() {
510 30
		$type_cls = $this->_element->typeClass();
511 30
		$tag = $this->_element->tag();
512 30
		if ($type_cls == Identifier::CLASS_UNIVERSAL) {
513 29
			return Element::tagToName($tag);
514
		}
515 1
		return Identifier::classToName($type_cls) . " TAG $tag";
516
	}
517
	
518
	/**
519
	 *
520
	 * @deprecated Use any <code>as*</code> accessor method first to ensure
521
	 *             type strictness.
522
	 * @see \ASN1\Feature\Encodable::toDER()
523
	 * @return string
524
	 */
525
	public function toDER() {
526
		return $this->_element->toDER();
527
	}
528
	
529
	/**
530
	 *
531
	 * @deprecated Use any <code>as*</code> accessor method first to ensure
532
	 *             type strictness.
533
	 * @see \ASN1\Feature\ElementBase::typeClass()
534
	 * @return int
535
	 */
536
	public function typeClass() {
537
		return $this->_element->typeClass();
538
	}
539
	
540
	/**
541
	 *
542
	 * @deprecated Use any <code>as*</code> accessor method first to ensure
543
	 *             type strictness.
544
	 * @see \ASN1\Feature\ElementBase::isConstructed()
545
	 * @return bool
546
	 */
547
	public function isConstructed() {
548
		return $this->_element->isConstructed();
549
	}
550
	
551
	/**
552
	 *
553
	 * @deprecated Use any <code>as*</code> accessor method first to ensure
554
	 *             type strictness.
555
	 * @see \ASN1\Feature\ElementBase::tag()
556
	 * @return int
557
	 */
558
	public function tag() {
559
		return $this->_element->tag();
560
	}
561
	
562
	/**
563
	 *
564
	 * @deprecated Use any <code>as*</code> accessor method first to ensure
565
	 *             type strictness.
566
	 * @see \ASN1\Feature\ElementBase::isType()
567
	 * @return bool
568
	 */
569
	public function isType($tag) {
570
		return $this->_element->isType($tag);
571
	}
572
	
573
	/**
574
	 *
575
	 * @deprecated Use any <code>as*</code> accessor method first to ensure
576
	 *             type strictness.
577
	 * @see \ASN1\Feature\ElementBase::expectType()
578
	 * @return ElementBase
579
	 */
580
	public function expectType($tag) {
581
		return $this->_element->expectType($tag);
582
	}
583
	
584
	/**
585
	 *
586
	 * @deprecated Use any <code>as*</code> accessor method first to ensure
587
	 *             type strictness.
588
	 * @see \ASN1\Feature\ElementBase::isTagged()
589
	 * @return bool
590
	 */
591
	public function isTagged() {
592
		return $this->_element->isTagged();
593
	}
594
	
595
	/**
596
	 *
597
	 * @deprecated Use any <code>as*</code> accessor method first to ensure
598
	 *             type strictness.
599
	 * @see \ASN1\Feature\ElementBase::expectTagged()
600
	 * @return TaggedType
601
	 */
602
	public function expectTagged($tag = null) {
603
		return $this->_element->expectTagged($tag);
604
	}
605
}
606