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 ( e2e876...92cc80 )
by Joni
03:04
created

UnspecifiedType::asIA5String()   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
	 * The wrapped element.
50
	 *
51
	 * @var Element
52
	 */
53
	private $_element;
54
	
55
	/**
56
	 * Constructor
57
	 *
58
	 * @param Element $el
59
	 */
60 89
	public function __construct(Element $el) {
61 89
		$this->_element = $el;
62 89
	}
63
	
64
	/**
65
	 * Initialize from ElementBase interface.
66
	 *
67
	 * @param ElementBase $el
68
	 * @return self
69
	 */
70 2
	public static function fromElementBase(ElementBase $el) {
71
		// if element is already wrapped
72 2
		if ($el instanceof self) {
73 1
			return $el;
74
		}
75 1
		return new self($el->asElement());
76
	}
77
	
78
	/**
79
	 * Compatibility method to dispatch calls to the wrapped element.
80
	 *
81
	 * @deprecated Use <code>as*</code> accessor methods to ensure strict type
82
	 * @param string $mtd Method name
83
	 * @param array $args Arguments
84
	 * @return mixed
85
	 */
86
	public function __call($mtd, array $args) {
87
		return call_user_func_array([$this->_element, $mtd], $args);
88
	}
89
	
90
	/**
91
	 * Get the wrapped element as a context specific tagged type.
92
	 *
93
	 * @throws \UnexpectedValueException
94
	 * @return TaggedType
95
	 */
96 2
	public function asTagged() {
97 2
		if (!$this->_element instanceof TaggedType) {
98 1
			throw new \UnexpectedValueException(
99 1
				"Tagged element expected, got " . $this->_typeDescriptorString());
100
		}
101 1
		return $this->_element;
102
	}
103
	
104
	/**
105
	 * Get the wrapped element as a boolean type.
106
	 *
107
	 * @throws \UnexpectedValueException
108
	 * @return Boolean
109
	 */
110 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...
111 4
		if (!$this->_element instanceof Boolean) {
112 1
			throw new \UnexpectedValueException(
113 1
				$this->_generateExceptionMessage(Element::TYPE_BOOLEAN));
114
		}
115 3
		return $this->_element;
116
	}
117
	
118
	/**
119
	 * Get the wrapped element as an integer type.
120
	 *
121
	 * @throws \UnexpectedValueException
122
	 * @return Integer
123
	 */
124 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...
125 2
		if (!$this->_element instanceof Integer) {
126 1
			throw new \UnexpectedValueException(
127 1
				$this->_generateExceptionMessage(Element::TYPE_INTEGER));
128
		}
129 1
		return $this->_element;
130
	}
131
	
132
	/**
133
	 * Get the wrapped element as a bit string type.
134
	 *
135
	 * @throws \UnexpectedValueException
136
	 * @return BitString
137
	 */
138 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...
139 2
		if (!$this->_element instanceof BitString) {
140 1
			throw new \UnexpectedValueException(
141 1
				$this->_generateExceptionMessage(Element::TYPE_BIT_STRING));
142
		}
143 1
		return $this->_element;
144
	}
145
	
146
	/**
147
	 * Get the wrapped element as an octet string type.
148
	 *
149
	 * @throws \UnexpectedValueException
150
	 * @return OctetString
151
	 */
152 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...
153 2
		if (!$this->_element instanceof OctetString) {
154 1
			throw new \UnexpectedValueException(
155 1
				$this->_generateExceptionMessage(Element::TYPE_OCTET_STRING));
156
		}
157 1
		return $this->_element;
158
	}
159
	
160
	/**
161
	 * Get the wrapped element as a null type.
162
	 *
163
	 * @throws \UnexpectedValueException
164
	 * @return NullType
165
	 */
166 9 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...
167 9
		if (!$this->_element instanceof NullType) {
168 2
			throw new \UnexpectedValueException(
169 2
				$this->_generateExceptionMessage(Element::TYPE_NULL));
170
		}
171 7
		return $this->_element;
172
	}
173
	
174
	/**
175
	 * Get the wrapped element as an object identifier type.
176
	 *
177
	 * @throws \UnexpectedValueException
178
	 * @return ObjectIdentifier
179
	 */
180 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...
181 2
		if (!$this->_element instanceof ObjectIdentifier) {
182 1
			throw new \UnexpectedValueException(
183 1
				$this->_generateExceptionMessage(
184 1
					Element::TYPE_OBJECT_IDENTIFIER));
185
		}
186 1
		return $this->_element;
187
	}
188
	
189
	/**
190
	 * Get the wrapped element as an object descriptor type.
191
	 *
192
	 * @throws \UnexpectedValueException
193
	 * @return ObjectDescriptor
194
	 */
195 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...
196 2
		if (!$this->_element instanceof ObjectDescriptor) {
197 1
			throw new \UnexpectedValueException(
198 1
				$this->_generateExceptionMessage(
199 1
					Element::TYPE_OBJECT_DESCRIPTOR));
200
		}
201 1
		return $this->_element;
202
	}
203
	
204
	/**
205
	 * Get the wrapped element as a real type.
206
	 *
207
	 * @throws \UnexpectedValueException
208
	 * @return Real
209
	 */
210 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...
211 2
		if (!$this->_element instanceof Real) {
212 1
			throw new \UnexpectedValueException(
213 1
				$this->_generateExceptionMessage(Element::TYPE_REAL));
214
		}
215 1
		return $this->_element;
216
	}
217
	
218
	/**
219
	 * Get the wrapped element as an enumerated type.
220
	 *
221
	 * @throws \UnexpectedValueException
222
	 * @return Enumerated
223
	 */
224 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...
225 2
		if (!$this->_element instanceof Enumerated) {
226 1
			throw new \UnexpectedValueException(
227 1
				$this->_generateExceptionMessage(Element::TYPE_ENUMERATED));
228
		}
229 1
		return $this->_element;
230
	}
231
	
232
	/**
233
	 * Get the wrapped element as a UTF8 string type.
234
	 *
235
	 * @throws \UnexpectedValueException
236
	 * @return UTF8String
237
	 */
238 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...
239 2
		if (!$this->_element instanceof UTF8String) {
240 1
			throw new \UnexpectedValueException(
241 1
				$this->_generateExceptionMessage(Element::TYPE_UTF8_STRING));
242
		}
243 1
		return $this->_element;
244
	}
245
	
246
	/**
247
	 * Get the wrapped element as a relative OID type.
248
	 *
249
	 * @throws \UnexpectedValueException
250
	 * @return RelativeOID
251
	 */
252 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...
253 2
		if (!$this->_element instanceof RelativeOID) {
254 1
			throw new \UnexpectedValueException(
255 1
				$this->_generateExceptionMessage(Element::TYPE_RELATIVE_OID));
256
		}
257 1
		return $this->_element;
258
	}
259
	
260
	/**
261
	 * Get the wrapped element as a sequence type.
262
	 *
263
	 * @throws \UnexpectedValueException
264
	 * @return Sequence
265
	 */
266 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...
267 2
		if (!$this->_element instanceof Sequence) {
268 1
			throw new \UnexpectedValueException(
269 1
				$this->_generateExceptionMessage(Element::TYPE_SEQUENCE));
270
		}
271 1
		return $this->_element;
272
	}
273
	
274
	/**
275
	 * Get the wrapped element as a set type.
276
	 *
277
	 * @throws \UnexpectedValueException
278
	 * @return Set
279
	 */
280 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...
281 2
		if (!$this->_element instanceof Set) {
282 1
			throw new \UnexpectedValueException(
283 1
				$this->_generateExceptionMessage(Element::TYPE_SET));
284
		}
285 1
		return $this->_element;
286
	}
287
	
288
	/**
289
	 * Get the wrapped element as a numeric string type.
290
	 *
291
	 * @throws \UnexpectedValueException
292
	 * @return NumericString
293
	 */
294 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...
295 2
		if (!$this->_element instanceof NumericString) {
296 1
			throw new \UnexpectedValueException(
297 1
				$this->_generateExceptionMessage(Element::TYPE_NUMERIC_STRING));
298
		}
299 1
		return $this->_element;
300
	}
301
	
302
	/**
303
	 * Get the wrapped element as a printable string type.
304
	 *
305
	 * @throws \UnexpectedValueException
306
	 * @return PrintableString
307
	 */
308 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...
309 2
		if (!$this->_element instanceof PrintableString) {
310 1
			throw new \UnexpectedValueException(
311 1
				$this->_generateExceptionMessage(Element::TYPE_PRINTABLE_STRING));
312
		}
313 1
		return $this->_element;
314
	}
315
	
316
	/**
317
	 * Get the wrapped element as a T61 string type.
318
	 *
319
	 * @throws \UnexpectedValueException
320
	 * @return T61String
321
	 */
322 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...
323 2
		if (!$this->_element instanceof T61String) {
324 1
			throw new \UnexpectedValueException(
325 1
				$this->_generateExceptionMessage(Element::TYPE_T61_STRING));
326
		}
327 1
		return $this->_element;
328
	}
329
	
330
	/**
331
	 * Get the wrapped element as a videotex string type.
332
	 *
333
	 * @throws \UnexpectedValueException
334
	 * @return VideotexString
335
	 */
336 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...
337 2
		if (!$this->_element instanceof VideotexString) {
338 1
			throw new \UnexpectedValueException(
339 1
				$this->_generateExceptionMessage(Element::TYPE_VIDEOTEX_STRING));
340
		}
341 1
		return $this->_element;
342
	}
343
	
344
	/**
345
	 * Get the wrapped element as a IA6 string type.
346
	 *
347
	 * @throws \UnexpectedValueException
348
	 * @return IA5String
349
	 */
350 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...
351 2
		if (!$this->_element instanceof IA5String) {
352 1
			throw new \UnexpectedValueException(
353 1
				$this->_generateExceptionMessage(Element::TYPE_IA5_STRING));
354
		}
355 1
		return $this->_element;
356
	}
357
	
358
	/**
359
	 * Get the wrapped element as an UTC time type.
360
	 *
361
	 * @throws \UnexpectedValueException
362
	 * @return UTCTime
363
	 */
364 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...
365 2
		if (!$this->_element instanceof UTCTime) {
366 1
			throw new \UnexpectedValueException(
367 1
				$this->_generateExceptionMessage(Element::TYPE_UTC_TIME));
368
		}
369 1
		return $this->_element;
370
	}
371
	
372
	/**
373
	 * Get the wrapped element as a generalized time type.
374
	 *
375
	 * @throws \UnexpectedValueException
376
	 * @return GeneralizedTime
377
	 */
378 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...
379 2
		if (!$this->_element instanceof GeneralizedTime) {
380 1
			throw new \UnexpectedValueException(
381 1
				$this->_generateExceptionMessage(Element::TYPE_GENERALIZED_TIME));
382
		}
383 1
		return $this->_element;
384
	}
385
	
386
	/**
387
	 * Get the wrapped element as a graphic string type.
388
	 *
389
	 * @throws \UnexpectedValueException
390
	 * @return GraphicString
391
	 */
392 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...
393 2
		if (!$this->_element instanceof GraphicString) {
394 1
			throw new \UnexpectedValueException(
395 1
				$this->_generateExceptionMessage(Element::TYPE_GRAPHIC_STRING));
396
		}
397 1
		return $this->_element;
398
	}
399
	
400
	/**
401
	 * Get the wrapped element as a visible string type.
402
	 *
403
	 * @throws \UnexpectedValueException
404
	 * @return VisibleString
405
	 */
406 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...
407 2
		if (!$this->_element instanceof VisibleString) {
408 1
			throw new \UnexpectedValueException(
409 1
				$this->_generateExceptionMessage(Element::TYPE_VISIBLE_STRING));
410
		}
411 1
		return $this->_element;
412
	}
413
	
414
	/**
415
	 * Get the wrapped element as a general string type.
416
	 *
417
	 * @throws \UnexpectedValueException
418
	 * @return GeneralString
419
	 */
420 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...
421 2
		if (!$this->_element instanceof GeneralString) {
422 1
			throw new \UnexpectedValueException(
423 1
				$this->_generateExceptionMessage(Element::TYPE_GENERAL_STRING));
424
		}
425 1
		return $this->_element;
426
	}
427
	
428
	/**
429
	 * Get the wrapped element as a universal string type.
430
	 *
431
	 * @throws \UnexpectedValueException
432
	 * @return UniversalString
433
	 */
434 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...
435 2
		if (!$this->_element instanceof UniversalString) {
436 1
			throw new \UnexpectedValueException(
437 1
				$this->_generateExceptionMessage(Element::TYPE_UNIVERSAL_STRING));
438
		}
439 1
		return $this->_element;
440
	}
441
	
442
	/**
443
	 * Get the wrapped element as a character string type.
444
	 *
445
	 * @throws \UnexpectedValueException
446
	 * @return CharacterString
447
	 */
448 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...
449 2
		if (!$this->_element instanceof CharacterString) {
450 1
			throw new \UnexpectedValueException(
451 1
				$this->_generateExceptionMessage(Element::TYPE_CHARACTER_STRING));
452
		}
453 1
		return $this->_element;
454
	}
455
	
456
	/**
457
	 * Get the wrapped element as a BMP string type.
458
	 *
459
	 * @throws \UnexpectedValueException
460
	 * @return BMPString
461
	 */
462 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...
463 2
		if (!$this->_element instanceof BMPString) {
464 1
			throw new \UnexpectedValueException(
465 1
				$this->_generateExceptionMessage(Element::TYPE_BMP_STRING));
466
		}
467 1
		return $this->_element;
468
	}
469
	
470
	/**
471
	 * Get the wrapped element as any string type.
472
	 *
473
	 * @throws \UnexpectedValueException
474
	 * @return StringType
475
	 */
476 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...
477 2
		if (!$this->_element instanceof StringType) {
478 1
			throw new \UnexpectedValueException(
479 1
				$this->_generateExceptionMessage(Element::TYPE_STRING));
480
		}
481 1
		return $this->_element;
482
	}
483
	
484
	/**
485
	 * Get the wrapped element as any time type.
486
	 *
487
	 * @throws \UnexpectedValueException
488
	 * @return TimeType
489
	 */
490 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...
491 2
		if (!$this->_element instanceof TimeType) {
492 1
			throw new \UnexpectedValueException(
493 1
				$this->_generateExceptionMessage(Element::TYPE_TIME));
494
		}
495 1
		return $this->_element;
496
	}
497
	
498
	/**
499
	 * Generate message for exceptions thrown by <code>as*</code> methods.
500
	 *
501
	 * @param int $tag Type tag of the expected element
502
	 * @return string
503
	 */
504 29
	private function _generateExceptionMessage($tag) {
505 29
		return Element::tagToName($tag) . " expected, got " .
506 29
			 $this->_typeDescriptorString() . ".";
507
	}
508
	
509
	/**
510
	 * Get textual description of the wrapped element for debugging purposes.
511
	 *
512
	 * @return string
513
	 */
514 30
	private function _typeDescriptorString() {
515 30
		$type_cls = $this->_element->typeClass();
516 30
		$tag = $this->_element->tag();
517 30
		if ($type_cls == Identifier::CLASS_UNIVERSAL) {
518 29
			return Element::tagToName($tag);
519
		}
520 1
		return Identifier::classToName($type_cls) . " TAG $tag";
521
	}
522
	
523
	/**
524
	 *
525
	 * @see \ASN1\Feature\Encodable::toDER()
526
	 * @return string
527
	 */
528 1
	public function toDER() {
529 1
		return $this->_element->toDER();
530
	}
531
	
532
	/**
533
	 *
534
	 * @see \ASN1\Feature\ElementBase::typeClass()
535
	 * @return int
536
	 */
537 2
	public function typeClass() {
538 2
		return $this->_element->typeClass();
539
	}
540
	
541
	/**
542
	 *
543
	 * @see \ASN1\Feature\ElementBase::isConstructed()
544
	 * @return bool
545
	 */
546 3
	public function isConstructed() {
547 3
		return $this->_element->isConstructed();
548
	}
549
	
550
	/**
551
	 *
552
	 * @see \ASN1\Feature\ElementBase::tag()
553
	 * @return int
554
	 */
555 9
	public function tag() {
556 9
		return $this->_element->tag();
557
	}
558
	
559
	/**
560
	 *
561
	 * @see \ASN1\Feature\ElementBase::isType()
562
	 * @return bool
563
	 */
564 1
	public function isType($tag) {
565 1
		return $this->_element->isType($tag);
566
	}
567
	
568
	/**
569
	 *
570
	 * @deprecated Use any <code>as*</code> accessor method first to ensure
571
	 *             type strictness.
572
	 * @see \ASN1\Feature\ElementBase::expectType()
573
	 * @return ElementBase
574
	 */
575
	public function expectType($tag) {
576
		return $this->_element->expectType($tag);
577
	}
578
	
579
	/**
580
	 *
581
	 * @see \ASN1\Feature\ElementBase::isTagged()
582
	 * @return bool
583
	 */
584 1
	public function isTagged() {
585 1
		return $this->_element->isTagged();
586
	}
587
	
588
	/**
589
	 *
590
	 * @deprecated Use any <code>as*</code> accessor method first to ensure
591
	 *             type strictness.
592
	 * @see \ASN1\Feature\ElementBase::expectTagged()
593
	 * @return TaggedType
594
	 */
595
	public function expectTagged($tag = null) {
596
		return $this->_element->expectTagged($tag);
597
	}
598
	
599
	/**
600
	 *
601
	 * @see \ASN1\Feature\ElementBase::asElement()
602
	 * @return Element
603
	 */
604 1
	public function asElement() {
605 1
		return $this->_element;
606
	}
607
}
608