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
Branch php72 (a7f01e)
by Joni
04:53
created

Attributes   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 2
cbo 5
dl 0
loc 106
ccs 36
cts 36
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A fromASN1() 0 17 2
A __construct() 0 3 1
A extensionRequest() 0 6 2
A toASN1() 0 8 1
A fromAttributeValues() 0 7 1
A hasExtensionRequest() 0 3 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\X509\CertificationRequest;
6
7
use Sop\ASN1\Type\Constructed\Set;
8
use Sop\ASN1\Type\UnspecifiedType;
9
use Sop\X501\ASN1\Attribute;
10
use Sop\X501\ASN1\AttributeValue\AttributeValue;
11
use Sop\X509\CertificationRequest\Attribute\ExtensionRequestValue;
12
use Sop\X509\Feature\AttributeContainer;
13
14
/**
15
 * Implements <i>Attributes</i> ASN.1 type as a <i>SET OF Attribute</i>.
16
 *
17
 * Used in <i>CertificationRequestInfo</i>.
18
 *
19
 * @see https://tools.ietf.org/html/rfc2986#section-4
20
 */
21
class Attributes implements \Countable, \IteratorAggregate
22
{
23
    use AttributeContainer;
24
25
    /**
26
     * Mapping from OID to attribute value class name.
27
     *
28
     * @internal
29
     *
30
     * @var array
31
     */
32
    const MAP_OID_TO_CLASS = [
33
        ExtensionRequestValue::OID => ExtensionRequestValue::class,
34
    ];
35
36
    /**
37
     * Constructor.
38
     *
39
     * @param Attribute ...$attribs Attribute objects
40
     */
41 8
    public function __construct(Attribute ...$attribs)
42
    {
43 8
        $this->_attributes = $attribs;
44 8
    }
45
46
    /**
47
     * Initialize from attribute values.
48
     *
49
     * @param AttributeValue ...$values
50
     *
51
     * @return self
52
     */
53 1
    public static function fromAttributeValues(AttributeValue ...$values): Attributes
54
    {
55 1
        $attribs = array_map(
56
            function (AttributeValue $value) {
57 1
                return $value->toAttribute();
58 1
            }, $values);
59 1
        return new self(...$attribs);
60
    }
61
62
    /**
63
     * Initialize from ASN.1.
64
     *
65
     * @param Set $set
66
     *
67
     * @return self
68
     */
69 4
    public static function fromASN1(Set $set): Attributes
70
    {
71 4
        $attribs = array_map(
72
            function (UnspecifiedType $el) {
73 4
                return Attribute::fromASN1($el->asSequence());
74 4
            }, $set->elements());
75
        // cast attributes
76 4
        $attribs = array_map(
77
            function (Attribute $attr) {
78 4
                $oid = $attr->oid();
79 4
                if (array_key_exists($oid, self::MAP_OID_TO_CLASS)) {
80 4
                    $cls = self::MAP_OID_TO_CLASS[$oid];
81 4
                    return $attr->castValues($cls);
82
                }
83 1
                return $attr;
84 4
            }, $attribs);
85 4
        return new self(...$attribs);
86
    }
87
88
    /**
89
     * Check whether extension request attribute is present.
90
     *
91
     * @return bool
92
     */
93 6
    public function hasExtensionRequest(): bool
94
    {
95 6
        return $this->has(ExtensionRequestValue::OID);
96
    }
97
98
    /**
99
     * Get extension request attribute value.
100
     *
101
     * @throws \LogicException
102
     *
103
     * @return ExtensionRequestValue
104
     */
105 4
    public function extensionRequest(): ExtensionRequestValue
106
    {
107 4
        if (!$this->hasExtensionRequest()) {
108 1
            throw new \LogicException('No extension request attribute.');
109
        }
110 3
        return $this->firstOf(ExtensionRequestValue::OID)->first();
1 ignored issue
show
Bug Best Practice introduced by
The expression return $this->firstOf(So...estValue::OID)->first() returns the type Sop\X501\ASN1\AttributeValue\AttributeValue which includes types incompatible with the type-hinted return Sop\X509\CertificationRe...e\ExtensionRequestValue.
Loading history...
111
    }
112
113
    /**
114
     * Generate ASN.1 structure.
115
     *
116
     * @return Set
117
     */
118 5
    public function toASN1(): Set
119
    {
120 5
        $elements = array_map(
121
            function (Attribute $attr) {
122 5
                return $attr->toASN1();
123 5
            }, array_values($this->_attributes));
124 5
        $set = new Set(...$elements);
125 5
        return $set->sortedSetOf();
126
    }
127
}
128