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

UserNoticeQualifier::_qualifierASN1()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 4
nop 0
crap 3
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\X509\Certificate\Extension\CertificatePolicy;
6
7
use Sop\ASN1\Element;
8
use Sop\ASN1\Type\Constructed\Sequence;
9
use Sop\ASN1\Type\UnspecifiedType;
10
11
/**
12
 * Implements <i>UserNotice</i> ASN.1 type used by
13
 * 'Certificate Policies' certificate extension.
14
 *
15
 * @see https://tools.ietf.org/html/rfc5280#section-4.2.1.4
16
 */
17
class UserNoticeQualifier extends PolicyQualifierInfo
18
{
19
    /**
20
     * Explicit notice text.
21
     *
22
     * @var null|DisplayText
23
     */
24
    protected $_text;
25
26
    /**
27
     * Notice reference.
28
     *
29
     * @var null|NoticeReference
30
     */
31
    protected $_ref;
32
33
    /**
34
     * Constructor.
35
     *
36
     * @param null|DisplayText     $text
37
     * @param null|NoticeReference $ref
38
     */
39 16
    public function __construct(?DisplayText $text = null,
40
        ?NoticeReference $ref = null)
41
    {
42 16
        $this->_oid = self::OID_UNOTICE;
43 16
        $this->_text = $text;
44 16
        $this->_ref = $ref;
45 16
    }
46
47
    /**
48
     * {@inheritdoc}
49
     *
50
     * @return self
51
     */
52 11
    public static function fromQualifierASN1(UnspecifiedType $el): PolicyQualifierInfo
53
    {
54 11
        $seq = $el->asSequence();
55 11
        $ref = null;
56 11
        $text = null;
57 11
        $idx = 0;
58 11
        if ($seq->has($idx, Element::TYPE_SEQUENCE)) {
59 10
            $ref = NoticeReference::fromASN1($seq->at($idx++)->asSequence());
60
        }
61 11
        if ($seq->has($idx, Element::TYPE_STRING)) {
62 11
            $text = DisplayText::fromASN1($seq->at($idx)->asString());
63
        }
64 11
        return new self($text, $ref);
65
    }
66
67
    /**
68
     * Whether explicit text is present.
69
     *
70
     * @return bool
71
     */
72 5
    public function hasExplicitText(): bool
73
    {
74 5
        return isset($this->_text);
75
    }
76
77
    /**
78
     * Get explicit text.
79
     *
80
     * @throws \LogicException If not set
81
     *
82
     * @return DisplayText
83
     */
84 5
    public function explicitText(): DisplayText
85
    {
86 5
        if (!$this->hasExplicitText()) {
87 1
            throw new \LogicException('explicitText not set.');
88
        }
89 4
        return $this->_text;
1 ignored issue
show
Bug Best Practice introduced by
The expression return $this->_text could return the type null which is incompatible with the type-hinted return Sop\X509\Certificate\Ext...icatePolicy\DisplayText. Consider adding an additional type-check to rule them out.
Loading history...
90
    }
91
92
    /**
93
     * Whether notice reference is present.
94
     *
95
     * @return bool
96
     */
97 4
    public function hasNoticeRef(): bool
98
    {
99 4
        return isset($this->_ref);
100
    }
101
102
    /**
103
     * Get notice reference.
104
     *
105
     * @throws \LogicException If not set
106
     *
107
     * @return NoticeReference
108
     */
109 4
    public function noticeRef(): NoticeReference
110
    {
111 4
        if (!$this->hasNoticeRef()) {
112 1
            throw new \LogicException('noticeRef not set.');
113
        }
114 3
        return $this->_ref;
1 ignored issue
show
Bug Best Practice introduced by
The expression return $this->_ref could return the type null which is incompatible with the type-hinted return Sop\X509\Certificate\Ext...ePolicy\NoticeReference. Consider adding an additional type-check to rule them out.
Loading history...
115
    }
116
117
    /**
118
     * {@inheritdoc}
119
     */
120 18
    protected function _qualifierASN1(): Element
121
    {
122 18
        $elements = [];
123 18
        if (isset($this->_ref)) {
124 16
            $elements[] = $this->_ref->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

124
            /** @scrutinizer ignore-call */ 
125
            $elements[] = $this->_ref->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...
125
        }
126 18
        if (isset($this->_text)) {
127 18
            $elements[] = $this->_text->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

127
            /** @scrutinizer ignore-call */ 
128
            $elements[] = $this->_text->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...
128
        }
129 18
        return new Sequence(...$elements);
130
    }
131
}
132