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 ( a640e0...4a8ae9 )
by Joni
03:42
created

ElementWrapper::asElement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace ASN1;
4
5
use ASN1\Component\Identifier;
6
use ASN1\Feature\ElementBase;
7
use ASN1\Type\Constructed\Sequence;
8
use ASN1\Type\Constructed\Set;
9
use ASN1\Type\Primitive\BitString;
10
use ASN1\Type\Primitive\BMPString;
11
use ASN1\Type\Primitive\Boolean;
12
use ASN1\Type\Primitive\CharacterString;
13
use ASN1\Type\Primitive\Enumerated;
14
use ASN1\Type\Primitive\GeneralizedTime;
15
use ASN1\Type\Primitive\GeneralString;
16
use ASN1\Type\Primitive\GraphicString;
17
use ASN1\Type\Primitive\IA5String;
18
use ASN1\Type\Primitive\Integer;
19
use ASN1\Type\Primitive\NullType;
20
use ASN1\Type\Primitive\NumericString;
21
use ASN1\Type\Primitive\ObjectDescriptor;
22
use ASN1\Type\Primitive\ObjectIdentifier;
23
use ASN1\Type\Primitive\OctetString;
24
use ASN1\Type\Primitive\PrintableString;
25
use ASN1\Type\Primitive\Real;
26
use ASN1\Type\Primitive\RelativeOID;
27
use ASN1\Type\Primitive\T61String;
28
use ASN1\Type\Primitive\UniversalString;
29
use ASN1\Type\Primitive\UTCTime;
30
use ASN1\Type\Primitive\UTF8String;
31
use ASN1\Type\Primitive\VideotexString;
32
use ASN1\Type\Primitive\VisibleString;
33
use ASN1\Type\StringType;
34
use ASN1\Type\TaggedType;
35
use ASN1\Type\TimeType;
36
37
38
/**
39
 * Decorator class to wrap an element without already knowing the specific
40
 * underlying type.
41
 *
42
 * Provides accessor methods to test the underlying type and return a type
43
 * hinted instance of the concrete element.
44
 */
45
class ElementWrapper
46
{
47
	/**
48
	 * Wrapped element.
49
	 *
50
	 * @var Element
51
	 */
52
	private $_element;
53
	
54
	/**
55
	 * Constructor
56
	 *
57
	 * @param Element $el
58
	 */
59 77
	public function __construct(Element $el) {
60 77
		$this->_element = $el;
61 77
	}
62
	
63
	/**
64
	 * Compatibility method to dispatch calls to wrapped element.
65
	 *
66
	 * @deprecated Use <code>as*</code> accessor methods to ensure strict type
67
	 * @param string $mtd Method name
68
	 * @param array $args Arguments
69
	 * @return mixed
70
	 */
71
	public function __call($mtd, array $args) {
72
		return call_user_func_array([$this->_element, $mtd], $args);
73
	}
74
	
75
	/**
76
	 * Get the wrapped element as an abstract type.
77
	 *
78
	 * @return ElementBase
79
	 */
80 1
	public function asElement() {
81 1
		return $this->_element;
82
	}
83
	
84
	/**
85
	 * Get the wrapped element as a context specific tagged type.
86
	 *
87
	 * @throws \UnexpectedValueException
88
	 * @return TaggedType
89
	 */
90 2
	public function asTagged() {
91 2
		if (!$this->_element instanceof TaggedType) {
92 1
			throw new \UnexpectedValueException(
93 1
				"Tagged element expected, got " . $this->_typeDescriptorString());
94
		}
95 1
		return $this->_element;
96
	}
97
	
98
	/**
99
	 * Get the wrapped element as a boolean type.
100
	 *
101
	 * @throws \UnexpectedValueException
102
	 * @return Boolean
103
	 */
104 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...
105 4
		if (!$this->_element instanceof Boolean) {
106 1
			throw new \UnexpectedValueException(
107 1
				$this->_generateExceptionMessage(Element::TYPE_BOOLEAN));
108
		}
109 3
		return $this->_element;
110
	}
111
	
112
	/**
113
	 * Get the wrapped element as an integer type.
114
	 *
115
	 * @throws \UnexpectedValueException
116
	 * @return Integer
117
	 */
118 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...
119 2
		if (!$this->_element instanceof Integer) {
120 1
			throw new \UnexpectedValueException(
121 1
				$this->_generateExceptionMessage(Element::TYPE_INTEGER));
122
		}
123 1
		return $this->_element;
124
	}
125
	
126
	/**
127
	 * Get the wrapped element as a bit string type.
128
	 *
129
	 * @throws \UnexpectedValueException
130
	 * @return BitString
131
	 */
132 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...
133 2
		if (!$this->_element instanceof BitString) {
134 1
			throw new \UnexpectedValueException(
135 1
				$this->_generateExceptionMessage(Element::TYPE_BIT_STRING));
136
		}
137 1
		return $this->_element;
138
	}
139
	
140
	/**
141
	 * Get the wrapped element as an octet string type.
142
	 *
143
	 * @throws \UnexpectedValueException
144
	 * @return OctetString
145
	 */
146 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...
147 2
		if (!$this->_element instanceof OctetString) {
148 1
			throw new \UnexpectedValueException(
149 1
				$this->_generateExceptionMessage(Element::TYPE_OCTET_STRING));
150
		}
151 1
		return $this->_element;
152
	}
153
	
154
	/**
155
	 * Get the wrapped element as a null type.
156
	 *
157
	 * @throws \UnexpectedValueException
158
	 * @return NullType
159
	 */
160 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...
161 7
		if (!$this->_element instanceof NullType) {
162 2
			throw new \UnexpectedValueException(
163 2
				$this->_generateExceptionMessage(Element::TYPE_NULL));
164
		}
165 5
		return $this->_element;
166
	}
167
	
168
	/**
169
	 * Get the wrapped element as an object identifier type.
170
	 *
171
	 * @throws \UnexpectedValueException
172
	 * @return ObjectIdentifier
173
	 */
174 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...
175 2
		if (!$this->_element instanceof ObjectIdentifier) {
176 1
			throw new \UnexpectedValueException(
177 1
				$this->_generateExceptionMessage(
178 1
					Element::TYPE_OBJECT_IDENTIFIER));
179
		}
180 1
		return $this->_element;
181
	}
182
	
183
	/**
184
	 * Get the wrapped element as an object descriptor type.
185
	 *
186
	 * @throws \UnexpectedValueException
187
	 * @return ObjectDescriptor
188
	 */
189 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...
190 2
		if (!$this->_element instanceof ObjectDescriptor) {
191 1
			throw new \UnexpectedValueException(
192 1
				$this->_generateExceptionMessage(
193 1
					Element::TYPE_OBJECT_DESCRIPTOR));
194
		}
195 1
		return $this->_element;
196
	}
197
	
198
	/**
199
	 * Get the wrapped element as a real type.
200
	 *
201
	 * @throws \UnexpectedValueException
202
	 * @return Real
203
	 */
204 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...
205 2
		if (!$this->_element instanceof Real) {
206 1
			throw new \UnexpectedValueException(
207 1
				$this->_generateExceptionMessage(Element::TYPE_REAL));
208
		}
209 1
		return $this->_element;
210
	}
211
	
212
	/**
213
	 * Get the wrapped element as an enumerated type.
214
	 *
215
	 * @throws \UnexpectedValueException
216
	 * @return Enumerated
217
	 */
218 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...
219 2
		if (!$this->_element instanceof Enumerated) {
220 1
			throw new \UnexpectedValueException(
221 1
				$this->_generateExceptionMessage(Element::TYPE_ENUMERATED));
222
		}
223 1
		return $this->_element;
224
	}
225
	
226
	/**
227
	 * Get the wrapped element as a UTF8 string type.
228
	 *
229
	 * @throws \UnexpectedValueException
230
	 * @return UTF8String
231
	 */
232 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...
233 2
		if (!$this->_element instanceof UTF8String) {
234 1
			throw new \UnexpectedValueException(
235 1
				$this->_generateExceptionMessage(Element::TYPE_UTF8_STRING));
236
		}
237 1
		return $this->_element;
238
	}
239
	
240
	/**
241
	 * Get the wrapped element as a relative OID type.
242
	 *
243
	 * @throws \UnexpectedValueException
244
	 * @return RelativeOID
245
	 */
246 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...
247 2
		if (!$this->_element instanceof RelativeOID) {
248 1
			throw new \UnexpectedValueException(
249 1
				$this->_generateExceptionMessage(Element::TYPE_RELATIVE_OID));
250
		}
251 1
		return $this->_element;
252
	}
253
	
254
	/**
255
	 * Get the wrapped element as a sequence type.
256
	 *
257
	 * @throws \UnexpectedValueException
258
	 * @return Sequence
259
	 */
260 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...
261 2
		if (!$this->_element instanceof Sequence) {
262 1
			throw new \UnexpectedValueException(
263 1
				$this->_generateExceptionMessage(Element::TYPE_SEQUENCE));
264
		}
265 1
		return $this->_element;
266
	}
267
	
268
	/**
269
	 * Get the wrapped element as a set type.
270
	 *
271
	 * @throws \UnexpectedValueException
272
	 * @return Set
273
	 */
274 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...
275 2
		if (!$this->_element instanceof Set) {
276 1
			throw new \UnexpectedValueException(
277 1
				$this->_generateExceptionMessage(Element::TYPE_SET));
278
		}
279 1
		return $this->_element;
280
	}
281
	
282
	/**
283
	 * Get the wrapped element as a numeric string type.
284
	 *
285
	 * @throws \UnexpectedValueException
286
	 * @return NumericString
287
	 */
288 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...
289 2
		if (!$this->_element instanceof NumericString) {
290 1
			throw new \UnexpectedValueException(
291 1
				$this->_generateExceptionMessage(Element::TYPE_NUMERIC_STRING));
292
		}
293 1
		return $this->_element;
294
	}
295
	
296
	/**
297
	 * Get the wrapped element as a printable string type.
298
	 *
299
	 * @throws \UnexpectedValueException
300
	 * @return PrintableString
301
	 */
302 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...
303 2
		if (!$this->_element instanceof PrintableString) {
304 1
			throw new \UnexpectedValueException(
305 1
				$this->_generateExceptionMessage(Element::TYPE_PRINTABLE_STRING));
306
		}
307 1
		return $this->_element;
308
	}
309
	
310
	/**
311
	 * Get the wrapped element as a T61 string type.
312
	 *
313
	 * @throws \UnexpectedValueException
314
	 * @return T61String
315
	 */
316 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...
317 2
		if (!$this->_element instanceof T61String) {
318 1
			throw new \UnexpectedValueException(
319 1
				$this->_generateExceptionMessage(Element::TYPE_T61_STRING));
320
		}
321 1
		return $this->_element;
322
	}
323
	
324
	/**
325
	 * Get the wrapped element as a videotex string type.
326
	 *
327
	 * @throws \UnexpectedValueException
328
	 * @return VideotexString
329
	 */
330 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...
331 2
		if (!$this->_element instanceof VideotexString) {
332 1
			throw new \UnexpectedValueException(
333 1
				$this->_generateExceptionMessage(Element::TYPE_VIDEOTEX_STRING));
334
		}
335 1
		return $this->_element;
336
	}
337
	
338
	/**
339
	 * Get the wrapped element as a IA6 string type.
340
	 *
341
	 * @throws \UnexpectedValueException
342
	 * @return IA5String
343
	 */
344 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...
345 2
		if (!$this->_element instanceof IA5String) {
346 1
			throw new \UnexpectedValueException(
347 1
				$this->_generateExceptionMessage(Element::TYPE_IA5_STRING));
348
		}
349 1
		return $this->_element;
350
	}
351
	
352
	/**
353
	 * Get the wrapped element as an UTC time type.
354
	 *
355
	 * @throws \UnexpectedValueException
356
	 * @return UTCTime
357
	 */
358 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...
359 2
		if (!$this->_element instanceof UTCTime) {
360 1
			throw new \UnexpectedValueException(
361 1
				$this->_generateExceptionMessage(Element::TYPE_UTC_TIME));
362
		}
363 1
		return $this->_element;
364
	}
365
	
366
	/**
367
	 * Get the wrapped element as a generalized time type.
368
	 *
369
	 * @throws \UnexpectedValueException
370
	 * @return GeneralizedTime
371
	 */
372 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...
373 2
		if (!$this->_element instanceof GeneralizedTime) {
374 1
			throw new \UnexpectedValueException(
375 1
				$this->_generateExceptionMessage(Element::TYPE_GENERALIZED_TIME));
376
		}
377 1
		return $this->_element;
378
	}
379
	
380
	/**
381
	 * Get the wrapped element as a graphic string type.
382
	 *
383
	 * @throws \UnexpectedValueException
384
	 * @return GraphicString
385
	 */
386 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...
387 2
		if (!$this->_element instanceof GraphicString) {
388 1
			throw new \UnexpectedValueException(
389 1
				$this->_generateExceptionMessage(Element::TYPE_GRAPHIC_STRING));
390
		}
391 1
		return $this->_element;
392
	}
393
	
394
	/**
395
	 * Get the wrapped element as a visible string type.
396
	 *
397
	 * @throws \UnexpectedValueException
398
	 * @return VisibleString
399
	 */
400 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...
401 2
		if (!$this->_element instanceof VisibleString) {
402 1
			throw new \UnexpectedValueException(
403 1
				$this->_generateExceptionMessage(Element::TYPE_VISIBLE_STRING));
404
		}
405 1
		return $this->_element;
406
	}
407
	
408
	/**
409
	 * Get the wrapped element as a general string type.
410
	 *
411
	 * @throws \UnexpectedValueException
412
	 * @return GeneralString
413
	 */
414 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...
415 2
		if (!$this->_element instanceof GeneralString) {
416 1
			throw new \UnexpectedValueException(
417 1
				$this->_generateExceptionMessage(Element::TYPE_GENERAL_STRING));
418
		}
419 1
		return $this->_element;
420
	}
421
	
422
	/**
423
	 * Get the wrapped element as a universal string type.
424
	 *
425
	 * @throws \UnexpectedValueException
426
	 * @return UniversalString
427
	 */
428 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...
429 2
		if (!$this->_element instanceof UniversalString) {
430 1
			throw new \UnexpectedValueException(
431 1
				$this->_generateExceptionMessage(Element::TYPE_UNIVERSAL_STRING));
432
		}
433 1
		return $this->_element;
434
	}
435
	
436
	/**
437
	 * Get the wrapped element as a character string type.
438
	 *
439
	 * @throws \UnexpectedValueException
440
	 * @return CharacterString
441
	 */
442 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...
443 2
		if (!$this->_element instanceof CharacterString) {
444 1
			throw new \UnexpectedValueException(
445 1
				$this->_generateExceptionMessage(Element::TYPE_CHARACTER_STRING));
446
		}
447 1
		return $this->_element;
448
	}
449
	
450
	/**
451
	 * Get the wrapped element as a BMP string type.
452
	 *
453
	 * @throws \UnexpectedValueException
454
	 * @return BMPString
455
	 */
456 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...
457 2
		if (!$this->_element instanceof BMPString) {
458 1
			throw new \UnexpectedValueException(
459 1
				$this->_generateExceptionMessage(Element::TYPE_BMP_STRING));
460
		}
461 1
		return $this->_element;
462
	}
463
	
464
	/**
465
	 * Get the wrapped element as any string type.
466
	 *
467
	 * @throws \UnexpectedValueException
468
	 * @return StringType
469
	 */
470 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...
471 2
		if (!$this->_element instanceof StringType) {
472 1
			throw new \UnexpectedValueException(
473 1
				$this->_generateExceptionMessage(Element::TYPE_STRING));
474
		}
475 1
		return $this->_element;
476
	}
477
	
478
	/**
479
	 * Get the wrapped element as any time type.
480
	 *
481
	 * @throws \UnexpectedValueException
482
	 * @return TimeType
483
	 */
484 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...
485 2
		if (!$this->_element instanceof TimeType) {
486 1
			throw new \UnexpectedValueException(
487 1
				$this->_generateExceptionMessage(Element::TYPE_TIME));
488
		}
489 1
		return $this->_element;
490
	}
491
	
492
	/**
493
	 * Generate message for exceptions thrown by <code>as*</code> methods.
494
	 *
495
	 * @param int $tag Type tag of the expected element
496
	 * @return string
497
	 */
498 29
	private function _generateExceptionMessage($tag) {
499 29
		return Element::tagToName($tag) . " expected, got " .
500 29
			 $this->_typeDescriptorString() . ".";
501
	}
502
	
503
	/**
504
	 * Get textual description of the wrapped element for debugging purposes.
505
	 *
506
	 * @return string
507
	 */
508 30
	private function _typeDescriptorString() {
509 30
		$type_cls = $this->_element->typeClass();
510 30
		$tag = $this->_element->tag();
511 30
		if ($type_cls == Identifier::CLASS_UNIVERSAL) {
512 29
			return Element::tagToName($tag);
513
		}
514 1
		return Identifier::classToName($type_cls) . " TAG $tag";
515
	}
516
}
517