OctetString::getEncodedValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
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\Asn1\UniversalTagID;
9
10
/**
11
 * ASN.1 element: OCTET STRING.
12
 */
13
class OctetString implements TaggableElement
14
{
15
    use TaggableElementTrait;
16
17
    /**
18
     * The value of the element.
19
     *
20
     * @var string
21
     */
22
    private $value;
23
24
    /**
25
     * Create a new instance.
26
     *
27
     * @param string $value the value of the element
28
     *
29
     * @return static
30
     */
31 3
    public static function create($value)
32
    {
33 3
        $result = new static();
34
35 3
        return $result->setValue($value);
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     *
41
     * @see \Ocsp\Asn1\Element::getClass()
42
     */
43 3
    public function getClass()
44
    {
45 3
        return static::CLASS_UNIVERSAL;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     *
51
     * @see \Ocsp\Asn1\Element::getTypeID()
52
     */
53 3
    public function getTypeID()
54
    {
55 3
        return UniversalTagID::OCTET_STRING;
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     *
61
     * @see \Ocsp\Asn1\Element::isConstructed()
62
     */
63 2
    public function isConstructed()
64
    {
65 2
        return false;
66
    }
67
68
    /**
69
     * Get the value of the element.
70
     *
71
     * @return string
72
     */
73 3
    public function getValue()
74
    {
75 3
        return $this->value;
76
    }
77
78
    /**
79
     * Update the value of the element.
80
     *
81
     * @param string $value
82
     *
83
     * @return $this
84
     */
85 3
    public function setValue($value)
86
    {
87 3
        $this->value = (string) $value;
88
89 3
        return $this;
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     *
95
     * @see \Ocsp\Asn1\Element::getEncodedValue()
96
     */
97 2
    public function getEncodedValue(Encoder $encoder)
98
    {
99 2
        return $encoder->encodeOctetString($this->getValue());
100
    }
101
}
102