RawPrimitive::getEncodedValue()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 10
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
namespace Ocsp\Asn1\Element;
4
5
use Ocsp\Asn1\Encoder;
6
use Ocsp\Asn1\TaggableElement;
7
use Ocsp\Asn1\TaggableElementTrait;
8
use Ocsp\Exception\Asn1EncodingException;
9
10
/**
11
 * An un-decoded ASN.1 PRIMITIVE element.
12
 */
13
class RawPrimitive implements TaggableElement
14
{
15
    use TaggableElementTrait;
16
17
    /**
18
     * The handle of the encoding.
19
     *
20
     * @var string
21
     */
22
    private $encoding;
23
24
    /**
25
     * The decoded type ID.
26
     *
27
     * @var int|string|\phpseclib\Math\BigInteger|\phpseclib3\Math\BigInteger
0 ignored issues
show
Bug introduced by
The type phpseclib\Math\BigInteger was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
28
     */
29
    private $typeID;
30
31
    /**
32
     * The class (the value of one of the Element::CLASS_... constants).
33
     *
34
     * @var string
35
     */
36
    private $class;
37
38
    /**
39
     * The not decoded bytes representing the value.
40
     *
41
     * @var string
42
     */
43
    private $rawEncodedValue;
44
45
    /**
46
     * Create a new instance.
47
     *
48
     * @param string $encoding the handle of the encoding
49
     * @param int|string|\phpseclib\Math\BigInteger|\phpseclib3\Math\BigInteger $typeID
50
     * @param string $class the class (the value of one of the Element::CLASS_... constants)
51
     * @param string $rawEncodedValue the not decoded bytes representing the value
52
     *
53
     * @return static
54
     */
55 3
    public static function create($encoding, $typeID, $class, $rawEncodedValue)
56
    {
57 3
        $result = new static();
58 3
        $result->encoding = $encoding;
59 3
        $result->typeID = $typeID;
60 3
        $result->class = $class;
61 3
        $result->rawEncodedValue = $rawEncodedValue;
62
63 3
        return $result;
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     *
69
     * @see \Ocsp\Asn1\Element::getClass()
70
     */
71 3
    public function getClass()
72
    {
73 3
        return $this->class;
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     *
79
     * @see \Ocsp\Asn1\Element::getTypeID()
80
     */
81 3
    public function getTypeID()
82
    {
83 3
        return $this->typeID;
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     *
89
     * @see \Ocsp\Asn1\Element::isConstructed()
90
     */
91
    public function isConstructed()
92
    {
93
        return false;
94
    }
95
96
    /**
97
     * Get the not decoded bytes representing the value.
98
     *
99
     * @return string
100
     */
101 3
    public function getRawEncodedValue()
102
    {
103 3
        return $this->rawEncodedValue;
104
    }
105
106
    /**
107
     * {@inheritdoc}
108
     *
109
     * @see \Ocsp\Asn1\Element::getEncodedValue()
110
     */
111
    public function getEncodedValue(Encoder $encoder)
112
    {
113
        if ($encoder->getEncodingHandle() === $this->encoding) {
114
            return $this->rawEncodedValue;
115
        }
116
        throw Asn1EncodingException::create('Unable to decode/encode an ASN.1 element');
117
    }
118
}
119