Completed
Push — master ( dd1269...21c3dd )
by Sam
02:11
created

Document   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 84
ccs 13
cts 26
cp 0.5
rs 10
wmc 11

8 Methods

Rating   Name   Duplication   Size   Complexity  
A read() 0 5 2
A append() 0 4 2
A toArray() 0 3 1
A offsetSet() 0 3 1
A write() 0 6 2
A offsetGet() 0 3 1
A offsetUnset() 0 3 1
A offsetExists() 0 3 1
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 1
    public function read(Buffer $buffer)
22
    {
23 1
        $count = $buffer->readInt();
24 1
        for ($i = 0; $i < $count; $i++) {
25 1
            $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 1
    }
28
29
    /**
30
     * @param Buffer $buffer
31
     */
32 1
    public function write(Buffer $buffer)
33
    {
34 1
        $buffer->writeInt(self::TYPE);
35 1
        $buffer->writeInt(count($this->lines));
36 1
        foreach ($this->lines as $line) {
37 1
            $buffer->writeString((string) $line, self::LENGTH);
38
        }
39 1
    }
40
41
    /**
42
     * @return array
43
     */
44 1
    public function toArray()
45
    {
46 1
        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