LongVariableNames   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 15
c 2
b 0
f 0
dl 0
loc 36
ccs 0
cts 14
cp 0
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A read() 0 8 2
A write() 0 9 2
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