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.

Attributes   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 141
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 13
eloc 26
dl 0
loc 141
ccs 30
cts 30
cp 1
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A role() 0 3 1
A hasChargingIdentity() 0 3 1
A hasRole() 0 3 1
A hasGroup() 0 3 1
A chargingIdentity() 0 3 1
A accessIdentity() 0 3 1
A group() 0 3 1
A hasAuthenticationInformation() 0 3 1
A roles() 0 7 1
A _castAttributeValues() 0 7 2
A hasAccessIdentity() 0 3 1
A authenticationInformation() 0 3 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\X509\AttributeCertificate;
6
7
use Sop\X501\ASN1\Attribute;
8
use Sop\X501\ASN1\AttributeType;
9
use Sop\X501\ASN1\Collection\SequenceOfAttributes;
10
use Sop\X509\AttributeCertificate\Attribute\AccessIdentityAttributeValue;
11
use Sop\X509\AttributeCertificate\Attribute\AuthenticationInfoAttributeValue;
12
use Sop\X509\AttributeCertificate\Attribute\ChargingIdentityAttributeValue;
13
use Sop\X509\AttributeCertificate\Attribute\GroupAttributeValue;
14
use Sop\X509\AttributeCertificate\Attribute\RoleAttributeValue;
15
16
/**
17
 * Implements *Attributes* ASN.1 type of *AttributeCertificateInfo*.
18
 *
19
 * @see https://tools.ietf.org/html/rfc5755#section-4.1
20
 * @see https://tools.ietf.org/html/rfc5755#section-4.2.7
21
 */
22
class Attributes extends SequenceOfAttributes
23
{
24
    /**
25
     * Mapping from OID to attribute value class name.
26
     *
27
     * @internal
28
     *
29
     * @var array
30
     */
31
    const MAP_OID_TO_CLASS = [
32
        AccessIdentityAttributeValue::OID => AccessIdentityAttributeValue::class,
33
        AuthenticationInfoAttributeValue::OID => AuthenticationInfoAttributeValue::class,
34
        ChargingIdentityAttributeValue::OID => ChargingIdentityAttributeValue::class,
35
        GroupAttributeValue::OID => GroupAttributeValue::class,
36
        AttributeType::OID_ROLE => RoleAttributeValue::class,
37
    ];
38
39
    /**
40
     * Check whether 'Access Identity' attribute is present.
41
     *
42
     * @return bool
43
     */
44 1
    public function hasAccessIdentity(): bool
45
    {
46 1
        return $this->has(AccessIdentityAttributeValue::OID);
47
    }
48
49
    /**
50
     * Get the first 'Access Identity' attribute value.
51
     *
52
     * @return AccessIdentityAttributeValue
53
     */
54 1
    public function accessIdentity(): AccessIdentityAttributeValue
55
    {
56 1
        return $this->firstOf(AccessIdentityAttributeValue::OID)->first();
57
    }
58
59
    /**
60
     * Check whether 'Service Authentication Information' attribute is present.
61
     *
62
     * @return bool
63
     */
64 1
    public function hasAuthenticationInformation(): bool
65
    {
66 1
        return $this->has(AuthenticationInfoAttributeValue::OID);
67
    }
68
69
    /**
70
     * Get the first 'Service Authentication Information' attribute value.
71
     *
72
     * @return AuthenticationInfoAttributeValue
73
     */
74 1
    public function authenticationInformation(): AuthenticationInfoAttributeValue
75
    {
76 1
        return $this->firstOf(AuthenticationInfoAttributeValue::OID)->first();
77
    }
78
79
    /**
80
     * Check whether 'Charging Identity' attribute is present.
81
     *
82
     * @return bool
83
     */
84 1
    public function hasChargingIdentity(): bool
85
    {
86 1
        return $this->has(ChargingIdentityAttributeValue::OID);
87
    }
88
89
    /**
90
     * Get the first 'Charging Identity' attribute value.
91
     *
92
     * @return ChargingIdentityAttributeValue
93
     */
94 1
    public function chargingIdentity(): ChargingIdentityAttributeValue
95
    {
96 1
        return $this->firstOf(ChargingIdentityAttributeValue::OID)->first();
97
    }
98
99
    /**
100
     * Check whether 'Group' attribute is present.
101
     *
102
     * @return bool
103
     */
104 1
    public function hasGroup(): bool
105
    {
106 1
        return $this->has(GroupAttributeValue::OID);
107
    }
108
109
    /**
110
     * Get the first 'Group' attribute value.
111
     *
112
     * @return GroupAttributeValue
113
     */
114 1
    public function group(): GroupAttributeValue
115
    {
116 1
        return $this->firstOf(GroupAttributeValue::OID)->first();
117
    }
118
119
    /**
120
     * Check whether 'Role' attribute is present.
121
     *
122
     * @return bool
123
     */
124 1
    public function hasRole(): bool
125
    {
126 1
        return $this->has(AttributeType::OID_ROLE);
127
    }
128
129
    /**
130
     * Get the first 'Role' attribute value.
131
     *
132
     * @return RoleAttributeValue
133
     */
134 1
    public function role(): RoleAttributeValue
135
    {
136 1
        return $this->firstOf(AttributeType::OID_ROLE)->first();
137
    }
138
139
    /**
140
     * Get all 'Role' attribute values.
141
     *
142
     * @return RoleAttributeValue[]
143
     */
144 2
    public function roles(): array
145
    {
146 2
        return array_merge([],
147 2
            ...array_map(
148
                function (Attribute $attr) {
149 2
                    return $attr->values();
150 2
                }, $this->allOf(AttributeType::OID_ROLE)));
151
    }
152
153
    /**
154
     * {@inheritdoc}
155
     */
156 6
    protected static function _castAttributeValues(Attribute $attribute): Attribute
157
    {
158 6
        $oid = $attribute->oid();
159 6
        if (isset(self::MAP_OID_TO_CLASS[$oid])) {
160 6
            return $attribute->castValues(self::MAP_OID_TO_CLASS[$oid]);
161
        }
162 1
        return $attribute;
163
    }
164
}
165