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 ( ec3172...fb818e )
by Joni
06:18
created

Attributes::roles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
crap 1
1
<?php
2
3
namespace X509\AttributeCertificate;
4
5
use ASN1\Type\Constructed\Sequence;
6
use ASN1\Type\UnspecifiedType;
7
use X501\ASN1\Attribute;
8
use X501\ASN1\AttributeType;
9
use X501\ASN1\AttributeValue\AttributeValue;
10
use X509\AttributeCertificate\Attribute\AccessIdentityAttributeValue;
11
use X509\AttributeCertificate\Attribute\AuthenticationInfoAttributeValue;
12
use X509\AttributeCertificate\Attribute\ChargingIdentityAttributeValue;
13
use X509\AttributeCertificate\Attribute\GroupAttributeValue;
14
use X509\AttributeCertificate\Attribute\RoleAttributeValue;
15
use X509\Feature\AttributeContainer;
16
17
18
/**
19
 * Implements <i>Attributes</i> ASN.1 type as a <i>SEQUENCE OF Attribute</i>.
20
 *
21
 * Used in <i>AttributeCertificateInfo</i>.
22
 *
23
 * @link https://tools.ietf.org/html/rfc5755#section-4.1
24
 * @link https://tools.ietf.org/html/rfc5755#section-4.2.7
25
 */
26
class Attributes implements \Countable, \IteratorAggregate
27
{
28
	use AttributeContainer;
29
	
30
	/**
31
	 * Mapping from OID to attribute value class name.
32
	 *
33
	 * @internal
34
	 *
35
	 * @var array
36
	 */
37
	const MAP_OID_TO_CLASS = array(
38
		/* @formatter:off */
39
		AccessIdentityAttributeValue::OID => AccessIdentityAttributeValue::class,
40
		AuthenticationInfoAttributeValue::OID => AuthenticationInfoAttributeValue::class,
41
		ChargingIdentityAttributeValue::OID => ChargingIdentityAttributeValue::class,
42
		GroupAttributeValue::OID => GroupAttributeValue::class,
43
		AttributeType::OID_ROLE => RoleAttributeValue::class
44
		/* @formatter:on */
45
	);
46
	
47
	/**
48
	 * Constructor
49
	 *
50
	 * @param Attribute ...$attribs
51
	 */
52 14
	public function __construct(Attribute ...$attribs) {
53 14
		$this->_attributes = $attribs;
54 14
	}
55
	
56
	/**
57
	 * Initialize from attribute values.
58
	 *
59
	 * @param AttributeValue ...$values
60
	 * @return self
61
	 */
62 8
	public static function fromAttributeValues(AttributeValue ...$values) {
63 8
		$attribs = array_map(
64
			function (AttributeValue $value) {
65 8
				return $value->toAttribute();
66 8
			}, $values);
67 8
		return new self(...$attribs);
68
	}
69
	
70
	/**
71
	 * Initialize from ASN.1.
72
	 *
73
	 * @param Sequence $seq
74
	 * @return self
75
	 */
76 6
	public static function fromASN1(Sequence $seq) {
77 6
		$attribs = array_map(
78
			function (UnspecifiedType $el) {
79 6
				return Attribute::fromASN1($el->asSequence());
80 6
			}, $seq->elements());
81
		// cast attributes
82 6
		$attribs = array_map(
83
			function (Attribute $attr) {
84 6
				$oid = $attr->oid();
85 6
				if (array_key_exists($oid, self::MAP_OID_TO_CLASS)) {
86 6
					$cls = self::MAP_OID_TO_CLASS[$oid];
87 6
					$attr = $attr->castValues($cls);
88 6
				}
89 6
				return $attr;
90 6
			}, $attribs);
91 6
		return new self(...$attribs);
92
	}
93
	
94
	/**
95
	 * Check whether 'Access Identity' attribute is present.
96
	 *
97
	 * @return bool
98
	 */
99 1
	public function hasAccessIdentity() {
100 1
		return $this->has(AccessIdentityAttributeValue::OID);
101
	}
102
	
103
	/**
104
	 * Get the first 'Access Identity' attribute value.
105
	 *
106
	 * @return AccessIdentityAttributeValue
107
	 */
108 1
	public function accessIdentity() {
109 1
		return $this->firstOf(AccessIdentityAttributeValue::OID)->first();
110
	}
111
	
112
	/**
113
	 * Check whether 'Service Authentication Information' attribute is present.
114
	 *
115
	 * @return bool
116
	 */
117 1
	public function hasAuthenticationInformation() {
118 1
		return $this->has(AuthenticationInfoAttributeValue::OID);
119
	}
120
	
121
	/**
122
	 * Get the first 'Service Authentication Information' attribute value.
123
	 *
124
	 * @return AuthenticationInfoAttributeValue
125
	 */
126 1
	public function authenticationInformation() {
127 1
		return $this->firstOf(AuthenticationInfoAttributeValue::OID)->first();
128
	}
129
	
130
	/**
131
	 * Check whether 'Charging Identity' attribute is present.
132
	 *
133
	 * @return bool
134
	 */
135 1
	public function hasChargingIdentity() {
136 1
		return $this->has(ChargingIdentityAttributeValue::OID);
137
	}
138
	
139
	/**
140
	 * Get the first 'Charging Identity' attribute value.
141
	 *
142
	 * @return ChargingIdentityAttributeValue
143
	 */
144 1
	public function chargingIdentity() {
145 1
		return $this->firstOf(ChargingIdentityAttributeValue::OID)->first();
146
	}
147
	
148
	/**
149
	 * Check whether 'Group' attribute is present.
150
	 *
151
	 * @return bool
152
	 */
153 1
	public function hasGroup() {
154 1
		return $this->has(GroupAttributeValue::OID);
155
	}
156
	
157
	/**
158
	 * Get the first 'Group' attribute value.
159
	 *
160
	 * @return GroupAttributeValue
161
	 */
162 1
	public function group() {
163 1
		return $this->firstOf(GroupAttributeValue::OID)->first();
164
	}
165
	
166
	/**
167
	 * Check whether 'Role' attribute is present.
168
	 *
169
	 * @return bool
170
	 */
171 1
	public function hasRole() {
172 1
		return $this->has(AttributeType::OID_ROLE);
173
	}
174
	
175
	/**
176
	 * Get the first 'Role' attribute value.
177
	 *
178
	 * @return RoleAttributeValue
179
	 */
180 1
	public function role() {
181 1
		return $this->firstOf(AttributeType::OID_ROLE)->first();
182
	}
183
	
184
	/**
185
	 * Get all 'Role' attribute values.
186
	 * 
187
	 * @return RoleAttributeValue[]
188
	 */
189 2
	public function roles() {
190 2
		return array_merge(array(), 
191 2
			...array_map(
192
				function (Attribute $attr) {
193 2
					return $attr->values();
194 2
				}, $this->allOf(AttributeType::OID_ROLE)));
195
	}
196
	
197
	/**
198
	 * Generate ASN.1 structure.
199
	 *
200
	 * @return Sequence
201
	 */
202 20
	public function toASN1() {
203 20
		$elements = array_map(
204 20
			function (Attribute $attr) {
205 12
				return $attr->toASN1();
206 20
			}, array_values($this->_attributes));
207 20
		return new Sequence(...$elements);
208
	}
209
}
210