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

RoleAttributeValue   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 154
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 10

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 10
dl 0
loc 154
ccs 43
cts 43
cp 1
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A roleName() 0 3 1
A hasRoleAuthority() 0 3 1
A stringValue() 0 3 1
A fromASN1() 0 12 2
A fromString() 0 4 1
A toASN1() 0 10 2
A _transcodedString() 0 3 1
A rfc2253String() 0 3 1
A equalityMatchingRule() 0 3 1
A __construct() 0 6 1
A roleAuthority() 0 6 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\X509\AttributeCertificate\Attribute;
6
7
use Sop\ASN1\Element;
8
use Sop\ASN1\Type\Constructed\Sequence;
9
use Sop\ASN1\Type\Tagged\ExplicitlyTaggedType;
10
use Sop\ASN1\Type\Tagged\ImplicitlyTaggedType;
11
use Sop\ASN1\Type\UnspecifiedType;
12
use Sop\X501\ASN1\AttributeType;
13
use Sop\X501\ASN1\AttributeValue\AttributeValue;
14
use Sop\X501\MatchingRule\BinaryMatch;
15
use Sop\X501\MatchingRule\MatchingRule;
16
use Sop\X509\GeneralName\GeneralName;
17
use Sop\X509\GeneralName\GeneralNames;
18
use Sop\X509\GeneralName\UniformResourceIdentifier;
19
20
/**
21
 * Implements value for 'Role' attribute.
22
 *
23
 * @see https://tools.ietf.org/html/rfc5755#section-4.4.5
24
 */
25
class RoleAttributeValue extends AttributeValue
26
{
27
    /**
28
     * Issuing authority.
29
     *
30
     * @var null|GeneralNames
31
     */
32
    protected $_roleAuthority;
33
34
    /**
35
     * Role name.
36
     *
37
     * @var GeneralName
38
     */
39
    protected $_roleName;
40
41
    /**
42
     * Constructor.
43
     *
44
     * @param GeneralName       $name      Role name
45
     * @param null|GeneralNames $authority Issuing authority
46
     */
47 15
    public function __construct(GeneralName $name,
48
        ?GeneralNames $authority = null)
49
    {
50 15
        $this->_roleAuthority = $authority;
51 15
        $this->_roleName = $name;
52 15
        $this->_oid = AttributeType::OID_ROLE;
53 15
    }
54
55
    /**
56
     * Initialize from a role string.
57
     *
58
     * @param string            $role_name Role name in URI format
59
     * @param null|GeneralNames $authority Issuing authority
60
     *
61
     * @return self
62
     */
63 2
    public static function fromString(string $role_name,
64
        ?GeneralNames $authority = null): self
65
    {
66 2
        return new self(new UniformResourceIdentifier($role_name), $authority);
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     *
72
     * @return self
73
     */
74 8
    public static function fromASN1(UnspecifiedType $el): AttributeValue
75
    {
76 8
        $seq = $el->asSequence();
77 8
        $authority = null;
78 8
        if ($seq->hasTagged(0)) {
79 1
            $authority = GeneralNames::fromASN1(
80 1
                $seq->getTagged(0)->asImplicit(Element::TYPE_SEQUENCE)
81 1
                    ->asSequence());
82
        }
83 8
        $name = GeneralName::fromASN1($seq->getTagged(1)
84 8
            ->asExplicit()->asTagged());
85 8
        return new self($name, $authority);
86
    }
87
88
    /**
89
     * Check whether issuing authority is present.
90
     *
91
     * @return bool
92
     */
93 2
    public function hasRoleAuthority(): bool
94
    {
95 2
        return isset($this->_roleAuthority);
96
    }
97
98
    /**
99
     * Get issuing authority.
100
     *
101
     * @throws \LogicException If not set
102
     *
103
     * @return GeneralNames
104
     */
105 2
    public function roleAuthority(): GeneralNames
106
    {
107 2
        if (!$this->hasRoleAuthority()) {
108 1
            throw new \LogicException('roleAuthority not set.');
109
        }
110 1
        return $this->_roleAuthority;
1 ignored issue
show
Bug Best Practice introduced by
The expression return $this->_roleAuthority could return the type null which is incompatible with the type-hinted return Sop\X509\GeneralName\GeneralNames. Consider adding an additional type-check to rule them out.
Loading history...
111
    }
112
113
    /**
114
     * Get role name.
115
     *
116
     * @return GeneralName
117
     */
118 2
    public function roleName(): GeneralName
119
    {
120 2
        return $this->_roleName;
121
    }
122
123
    /**
124
     * {@inheritdoc}
125
     */
126 17
    public function toASN1(): Element
127
    {
128 17
        $elements = [];
129 17
        if (isset($this->_roleAuthority)) {
130 4
            $elements[] = new ImplicitlyTaggedType(
131 4
                0, $this->_roleAuthority->toASN1());
1 ignored issue
show
Bug introduced by
The method toASN1() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

131
                0, $this->_roleAuthority->/** @scrutinizer ignore-call */ toASN1());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
132
        }
133 17
        $elements[] = new ExplicitlyTaggedType(
134 17
            1, $this->_roleName->toASN1());
135 17
        return new Sequence(...$elements);
136
    }
137
138
    /**
139
     * {@inheritdoc}
140
     */
141 3
    public function stringValue(): string
142
    {
143 3
        return '#' . bin2hex($this->toASN1()->toDER());
144
    }
145
146
    /**
147
     * {@inheritdoc}
148
     */
149 1
    public function equalityMatchingRule(): MatchingRule
150
    {
151 1
        return new BinaryMatch();
152
    }
153
154
    /**
155
     * {@inheritdoc}
156
     */
157 1
    public function rfc2253String(): string
158
    {
159 1
        return $this->stringValue();
160
    }
161
162
    /**
163
     * {@inheritdoc}
164
     */
165 1
    protected function _transcodedString(): string
166
    {
167 1
        return $this->stringValue();
168
    }
169
}
170