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

SvceAuthInfo::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
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\Primitive\OctetString;
10
use Sop\ASN1\Type\UnspecifiedType;
11
use Sop\X501\ASN1\AttributeValue\AttributeValue;
12
use Sop\X501\MatchingRule\BinaryMatch;
13
use Sop\X501\MatchingRule\MatchingRule;
14
use Sop\X509\GeneralName\GeneralName;
15
16
/**
17
 * Base class implementing <i>SvceAuthInfo</i> ASN.1 type used by
18
 * attribute certificate attribute values.
19
 *
20
 * @see https://tools.ietf.org/html/rfc5755#section-4.4.1
21
 */
22
abstract class SvceAuthInfo extends AttributeValue
23
{
24
    /**
25
     * Service.
26
     *
27
     * @var GeneralName
28
     */
29
    protected $_service;
30
31
    /**
32
     * Ident.
33
     *
34
     * @var GeneralName
35
     */
36
    protected $_ident;
37
38
    /**
39
     * Auth info.
40
     *
41
     * @var null|string
42
     */
43
    protected $_authInfo;
44
45
    /**
46
     * Constructor.
47
     *
48
     * @param GeneralName $service
49
     * @param GeneralName $ident
50
     * @param null|string $auth_info
51
     */
52 9
    public function __construct(GeneralName $service, GeneralName $ident,
53
        ?string $auth_info = null)
54
    {
55 9
        $this->_service = $service;
56 9
        $this->_ident = $ident;
57 9
        $this->_authInfo = $auth_info;
58 9
    }
59
60
    /**
61
     * {@inheritdoc}
62
     *
63
     * @return self
64
     */
65 5
    public static function fromASN1(UnspecifiedType $el): AttributeValue
66
    {
67 5
        $seq = $el->asSequence();
68 5
        $service = GeneralName::fromASN1($seq->at(0)->asTagged());
69 5
        $ident = GeneralName::fromASN1($seq->at(1)->asTagged());
70 5
        $auth_info = null;
71 5
        if ($seq->has(2, Element::TYPE_OCTET_STRING)) {
72 3
            $auth_info = $seq->at(2)->asString()->string();
73
        }
74 5
        return new static($service, $ident, $auth_info);
75
    }
76
77
    /**
78
     * Get service name.
79
     *
80
     * @return GeneralName
81
     */
82 2
    public function service(): GeneralName
83
    {
84 2
        return $this->_service;
85
    }
86
87
    /**
88
     * Get ident.
89
     *
90
     * @return GeneralName
91
     */
92 2
    public function ident(): GeneralName
93
    {
94 2
        return $this->_ident;
95
    }
96
97
    /**
98
     * Check whether authentication info is present.
99
     *
100
     * @return bool
101
     */
102 2
    public function hasAuthInfo(): bool
103
    {
104 2
        return isset($this->_authInfo);
105
    }
106
107
    /**
108
     * Get authentication info.
109
     *
110
     * @throws \LogicException If not set
111
     *
112
     * @return string
113
     */
114 2
    public function authInfo(): string
115
    {
116 2
        if (!$this->hasAuthInfo()) {
117 1
            throw new \LogicException('authInfo not set.');
118
        }
119 1
        return $this->_authInfo;
1 ignored issue
show
Bug Best Practice introduced by
The expression return $this->_authInfo could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
120
    }
121
122
    /**
123
     * {@inheritdoc}
124
     */
125 9
    public function toASN1(): Element
126
    {
127 9
        $elements = [$this->_service->toASN1(), $this->_ident->toASN1()];
128 9
        if (isset($this->_authInfo)) {
129 4
            $elements[] = new OctetString($this->_authInfo);
1 ignored issue
show
Bug introduced by
It seems like $this->_authInfo can also be of type null; however, parameter $string of Sop\ASN1\Type\Primitive\OctetString::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

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