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

Target   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 5
dl 0
loc 88
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromChosenASN1() 0 4 1
A fromASN1() 0 12 4
A type() 0 3 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\X509\Certificate\Extension\Target;
6
7
use Sop\ASN1\Element;
8
use Sop\ASN1\Type\TaggedType;
9
10
/**
11
 * Base class for <i>Target</i> ASN.1 CHOICE type.
12
 *
13
 * @see https://tools.ietf.org/html/rfc5755#section-4.3.2
14
 */
15
abstract class Target
16
{
17
    const TYPE_NAME = 0;
18
    const TYPE_GROUP = 1;
19
    const TYPE_CERT = 2;
20
21
    /**
22
     * Type tag.
23
     *
24
     * @var int
25
     */
26
    protected $_type;
27
28
    /**
29
     * Generate ASN.1 element.
30
     *
31
     * @return Element
32
     */
33
    abstract public function toASN1(): Element;
34
35
    /**
36
     * Get string value of the target.
37
     *
38
     * @return string
39
     */
40
    abstract public function string(): string;
41
42
    /**
43
     * Initialize concrete object from the chosen ASN.1 element.
44
     *
45
     * @param TaggedType $el
46
     *
47
     * @return self
48
     */
49 1
    public static function fromChosenASN1(TaggedType $el): Target
50
    {
51 1
        throw new \BadMethodCallException(
52 1
            __FUNCTION__ . ' must be implemented in the derived class.');
53
    }
54
55
    /**
56
     * Parse from ASN.1.
57
     *
58
     * @param TaggedType $el
59
     *
60
     * @throws \UnexpectedValueException
61
     *
62
     * @return self
63
     */
64 8
    public static function fromASN1(TaggedType $el): self
65
    {
66 8
        switch ($el->tag()) {
67 8
            case self::TYPE_NAME:
68 5
                return TargetName::fromChosenASN1($el->asExplicit()->asTagged());
69 5
            case self::TYPE_GROUP:
70 3
                return TargetGroup::fromChosenASN1($el->asExplicit()->asTagged());
71 2
            case self::TYPE_CERT:
72 1
                throw new \RuntimeException('targetCert not supported.');
73
        }
74 1
        throw new \UnexpectedValueException(
75 1
            'Target type ' . $el->tag() . ' not supported.');
76
    }
77
78
    /**
79
     * Get type tag.
80
     *
81
     * @return int
82
     */
83 8
    public function type(): int
84
    {
85 8
        return $this->_type;
86
    }
87
88
    /**
89
     * Check whether target is equal to another.
90
     *
91
     * @param Target $other
92
     *
93
     * @return bool
94
     */
95 8
    public function equals(Target $other): bool
96
    {
97 8
        if ($this->_type !== $other->_type) {
98 1
            return false;
99
        }
100 7
        if ($this->toASN1()->toDER() !== $other->toASN1()->toDER()) {
101 4
            return false;
102
        }
103 3
        return true;
104
    }
105
}
106