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 ( 96d802...e5ec4d )
by Joni
04:39
created

GeneralName::fromChosenASN1()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
ccs 4
cts 4
cp 1
rs 10
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace X509\GeneralName;
4
5
use ASN1\Element;
6
use ASN1\Type\TaggedType;
7
use ASN1\Type\UnspecifiedType;
8
9
10
/**
11
 * Implements <i>GeneralName</i> CHOICE with implicit tagging.
12
 *
13
 * @link https://tools.ietf.org/html/rfc5280#section-4.2.1.6
14
 */
15
abstract class GeneralName
16
{
17
	// GeneralName CHOICE tags
18
	const TAG_OTHER_NAME = 0;
19
	const TAG_RFC822_NAME = 1;
20
	const TAG_DNS_NAME = 2;
21
	const TAG_X400_ADDRESS = 3;
22
	const TAG_DIRECTORY_NAME = 4;
23
	const TAG_EDI_PARTY_NAME = 5;
24
	const TAG_URI = 6;
25
	const TAG_IP_ADDRESS = 7;
26
	const TAG_REGISTERED_ID = 8;
27
	
28
	/**
29
	 * Chosen tag.
30
	 *
31
	 * @var int $_tag
32
	 */
33
	protected $_tag;
34
	
35
	/**
36
	 * Get string value of the type.
37
	 *
38
	 * @return string
39
	 */
40
	abstract public function string();
41
	
42
	/**
43
	 * Get ASN.1 value in GeneralName CHOICE context.
44
	 *
45
	 * @return TaggedType
46
	 */
47
	abstract protected function _choiceASN1();
48
	
49
	/**
50
	 * Initialize concrete object from the chosen ASN.1 element.
51
	 *
52
	 * @param UnspecifiedType $el
53
	 * @return self
54
	 */
55 1
	public static function fromChosenASN1(UnspecifiedType $el) {
56 1
		throw new \BadMethodCallException(
57 1
			__FUNCTION__ . " must be implemented in the derived class.");
58 1
	}
59
	
60
	/**
61
	 * Initialize from ASN.1.
62
	 *
63
	 * @param TaggedType $el
64
	 * @throws \UnexpectedValueException
65
	 * @return self
66
	 */
67 57
	public static function fromASN1(TaggedType $el) {
68 57
		switch ($el->tag()) {
69
		// otherName
70 57
		case self::TAG_OTHER_NAME:
71 5
			return OtherName::fromChosenASN1(
72 5
				$el->asImplicit(Element::TYPE_SEQUENCE));
73
		// rfc822Name
74 56
		case self::TAG_RFC822_NAME:
75 5
			return RFC822Name::fromChosenASN1(
76 5
				$el->asImplicit(Element::TYPE_IA5_STRING));
77
		// dNSName
78 55
		case self::TAG_DNS_NAME:
79 9
			return DNSName::fromChosenASN1(
80 9
				$el->asImplicit(Element::TYPE_IA5_STRING));
81
		// x400Address
82 53
		case self::TAG_X400_ADDRESS:
83 2
			return X400Address::fromChosenASN1(
84 2
				$el->asImplicit(Element::TYPE_SEQUENCE));
85
		// directoryName
86 51
		case self::TAG_DIRECTORY_NAME:
87
			// because Name is a CHOICE, albeit having only one option,
88
			// explicit tagging must be used
89
			// (see X.680 07/2002 30.6.c)
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
90 31
			return DirectoryName::fromChosenASN1($el->asExplicit());
91
		// ediPartyName
92 35
		case self::TAG_EDI_PARTY_NAME:
93 2
			return EDIPartyName::fromChosenASN1(
94 2
				$el->asImplicit(Element::TYPE_SEQUENCE));
95
		// uniformResourceIdentifier
96 33
		case self::TAG_URI:
97 26
			return UniformResourceIdentifier::fromChosenASN1(
98 26
				$el->asImplicit(Element::TYPE_IA5_STRING));
99
		// iPAddress
100 11
		case self::TAG_IP_ADDRESS:
101 9
			return IPAddress::fromChosenASN1(
102 9
				$el->asImplicit(Element::TYPE_OCTET_STRING));
103
		// registeredID
104 6
		case self::TAG_REGISTERED_ID:
105 5
			return RegisteredID::fromChosenASN1(
106 5
				$el->asImplicit(Element::TYPE_OBJECT_IDENTIFIER));
107 1
		}
108 1
		throw new \UnexpectedValueException(
109 1
			"GeneralName type " . $el->tag() . " not supported.");
110
	}
111
	
112
	/**
113
	 * Get type tag.
114
	 *
115
	 * @return int
116
	 */
117 32
	public function tag() {
118 32
		return $this->_tag;
119
	}
120
	
121
	/**
122
	 * Generate ASN.1 element.
123
	 *
124
	 * @return Element
125
	 */
126 67
	public function toASN1() {
127 67
		return $this->_choiceASN1();
128
	}
129
	
130
	/**
131
	 * Get general name as a string.
132
	 *
133
	 * @return string
134
	 */
135 8
	public function __toString() {
136 8
		return $this->string();
137
	}
138
}
139