Passed
Push — master ( 386efc...fcbe67 )
by Sam
02:35
created

Document::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
namespace SPSS\Sav\Record;
4
5
use SPSS\Buffer;
6
use SPSS\Sav\Record;
7
8
class Document extends Record implements \ArrayAccess
9
{
10
    const TYPE = 6;
11
    const LENGTH = 80;
12
13
    /**
14
     * @var array
15
     */
16
    protected $lines = [];
17
18
    /**
19
     * @param Buffer $buffer
20
     */
21
    public function read(Buffer $buffer)
22
    {
23
        $count = $buffer->readInt();
24
        for ($i = 0; $i < $count; $i++) {
25
            $this->lines[] = trim($buffer->readString(self::LENGTH));
0 ignored issues
show
Bug introduced by
It seems like $buffer->readString(self::LENGTH) can also be of type false; however, parameter $str of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

25
            $this->lines[] = trim(/** @scrutinizer ignore-type */ $buffer->readString(self::LENGTH));
Loading history...
26
        }
27
    }
28
29
    /**
30
     * @param Buffer $buffer
31
     */
32
    public function write(Buffer $buffer)
33
    {
34
        $buffer->writeInt(self::TYPE);
35
        $buffer->writeInt(count($this->lines));
36
        foreach ($this->lines as $line) {
37
            $buffer->writeString((string) $line, self::LENGTH);
38
        }
39
    }
40
41
    /**
42
     * @return array
43
     */
44
    public function toArray()
45
    {
46
        return $this->lines;
47
    }
48
49
    /**
50
     * @param array $lines
51
     */
52
    public function append($lines)
53
    {
54
        foreach ($lines as $line) {
55
            $this->lines[] = $line;
56
        }
57
    }
58
59
    /**
60
     * @param mixed $offset
61
     * @return bool
62
     */
63
    public function offsetExists($offset)
64
    {
65
        return isset($this->lines[$offset]);
66
    }
67
68
    /**
69
     * @param mixed $offset
70
     * @return mixed
71
     */
72
    public function offsetGet($offset)
73
    {
74
        return $this->lines[$offset];
75
    }
76
77
    /**
78
     * @param mixed $offset
79
     * @param mixed $value
80
     */
81
    public function offsetSet($offset, $value)
82
    {
83
        $this->lines[$offset] = $value;
84
    }
85
86
    /**
87
     * @param mixed $offset
88
     */
89
    public function offsetUnset($offset)
90
    {
91
        unset($this->lines[$offset]);
92
    }
93
}
94