Debian Codegraph @

lib/3rdParty/composer/spomky-labs/cbor-php/src/ByteStringObject.php

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace CBOR;
6
7 use function strlen;
8
9 /**
10 * @see \CBOR\Test\ByteStringObjectTest
11 */
12 final class ByteStringObject extends AbstractCBORObject implements Normalizable
13 {
14 private const MAJOR_TYPE = self::MAJOR_TYPE_BYTE_STRING;
15
16 private string $value;
17
18 private ?string $length;
19
20 public function __construct(string $data)
21 {
22 [$additionalInformation, $length] = LengthCalculator::getLengthOfString($data);
23
24 parent::__construct(self::MAJOR_TYPE, $additionalInformation);
25 $this->length = $length;
26 $this->value = $data;
27 }
28
29 public function __toString(): string
30 {
31 $result = parent::__toString();
32 $result .= $this->length ?? '';
33
34 return $result . $this->value;
35 }
36
37 public static function create(string $data): self
38 {
39 return new self($data);
40 }
41
42 public function getValue(): string
43 {
44 return $this->value;
45 }
46
47 public function getLength(): int
48 {
49 return strlen($this->value);
50 }
51
52 public function normalize(): string
53 {
54 return $this->value;
55 }
56 }