AbstractDataType   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 11
c 1
b 0
f 0
dl 0
loc 101
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setOffset() 0 3 1
A assertNotEndOfFile() 0 4 2
A getByte() 0 3 1
A setContent() 0 3 1
A setEndianMode() 0 3 1
A setByte() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PBurggraf\BinaryUtilities\DataType;
6
7
use PBurggraf\BinaryUtilities\EndianType\AbstractEndianType;
8
use PBurggraf\BinaryUtilities\Exception\EndOfFileReachedException;
9
10
/**
11
 * @author Philip Burggraf <[email protected]>
12
 */
13
abstract class AbstractDataType
14
{
15
    /**
16
     * @var string
17
     */
18
    protected $content;
19
20
    /**
21
     * @var int
22
     */
23
    protected $offset;
24
25
    /**
26
     * @var AbstractEndianType
27
     */
28
    protected $endianMode;
29
30
    /**
31
     * @param string $content
32
     */
33
    public function setContent(string $content): void
34
    {
35
        $this->content = $content;
36
    }
37
38
    /**
39
     * @param int $offset
40
     */
41
    public function setOffset($offset): void
42
    {
43
        $this->offset = $offset;
44
    }
45
46
    /**
47
     * @param AbstractEndianType $endianType
48
     */
49
    public function setEndianMode(AbstractEndianType $endianType): void
50
    {
51
        $this->endianMode = $endianType;
52
    }
53
54
    /**
55
     * @param int $position
56
     *
57
     * @return int
58
     */
59
    protected function getByte(int $position): int
60
    {
61
        return (int) ord($this->content[$position]);
62
    }
63
64
    /**
65
     * @param int $position
66
     * @param int $data
67
     */
68
    protected function setByte(int $position, int $data): void
69
    {
70
        $this->content[$position] = chr($data);
71
    }
72
73
    /**
74
     * @throws EndOfFileReachedException
75
     */
76
    protected function assertNotEndOfFile(): void
77
    {
78
        if ($this->offset > strlen($this->content) - 1) {
79
            throw new EndOfFileReachedException();
80
        }
81
    }
82
83
    /**
84
     * @return array
85
     */
86
    abstract public function read(): array;
87
88
    /**
89
     * @param int $length
90
     *
91
     * @return array
92
     */
93
    abstract public function readArray(int $length): array;
94
95
    /**
96
     * @param int $data
97
     */
98
    abstract public function write(int $data): void;
99
100
    /**
101
     * @param int[] $data
102
     */
103
    abstract public function writeArray(array $data): void;
104
105
    /**
106
     * @return int
107
     */
108
    abstract public function newOffset(): int;
109
110
    /**
111
     * @return string
112
     */
113
    abstract public function newContent(): string;
114
}
115