LongVariableNames::write()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
ccs 0
cts 7
cp 0
crap 6
rs 10
1
<?php
2
3
namespace SPSS\Sav\Record\Info;
4
5
use SPSS\Buffer;
6
use SPSS\Sav\Record\Info;
7
8
class LongVariableNames extends Info
9
{
10
    const SUBTYPE = 13;
11
    const DELIMITER = "\t";
12
13
    /**
14
     * @var array
15
     */
16
    public $data = [];
17
18
    /**
19
     * @param Buffer $buffer
20
     */
21
    public function read(Buffer $buffer)
22
    {
23
        parent::read($buffer);
24
        $data = rtrim($buffer->readString($this->dataSize * $this->dataCount));
0 ignored issues
show
Bug introduced by
It seems like $buffer->readString($thi...ize * $this->dataCount) can also be of type false; however, parameter $str of rtrim() 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

24
        $data = rtrim(/** @scrutinizer ignore-type */ $buffer->readString($this->dataSize * $this->dataCount));
Loading history...
25
26
        foreach (explode(self::DELIMITER, $data) as $item) {
27
            list($key, $value) = explode('=', $item);
28
            $this->data[$key] = trim($value);
29
        }
30
    }
31
32
    /**
33
     * @param Buffer $buffer
34
     */
35
    public function write(Buffer $buffer)
36
    {
37
        $data = '';
38
        foreach ($this->data as $key => $value) {
39
            $data .= sprintf('%s=%s', $key, $value) . self::DELIMITER;
40
        }
41
        $this->dataCount = strlen($data);
42
        parent::write($buffer);
43
        $buffer->writeString($data);
44
    }
45
}
46