VeryLongString   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 16
c 2
b 0
f 0
dl 0
loc 32
ccs 0
cts 16
cp 0
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A read() 0 7 2
A write() 0 11 3
1
<?php
2
3
namespace SPSS\Sav\Record\Info;
4
5
use SPSS\Buffer;
6
use SPSS\Sav\Record\Info;
7
8
class VeryLongString extends Info
9
{
10
    const SUBTYPE = 14;
11
    const DELIMITER = "\t";
12
13
    /**
14
     * @param Buffer $buffer
15
     */
16
    public function read(Buffer $buffer)
17
    {
18
        parent::read($buffer);
19
        $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

19
        $data = rtrim(/** @scrutinizer ignore-type */ $buffer->readString($this->dataSize * $this->dataCount));
Loading history...
20
        foreach (explode(self::DELIMITER, $data) as $item) {
21
            list($key, $value) = explode('=', $item);
22
            $this->data[$key] = intval($value);
23
        }
24
    }
25
26
    /**
27
     * @param Buffer $buffer
28
     */
29
    public function write(Buffer $buffer)
30
    {
31
        if ($this->data) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->data of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
32
            $data = [];
33
            foreach ($this->data as $key => $value) {
34
                $data[] = sprintf('%s=%d%c', $key, $value, 0);
35
            }
36
            $data = join(self::DELIMITER, $data);
37
            $this->dataCount = strlen($data);
38
            parent::write($buffer);
39
            $buffer->writeString($data);
40
        }
41
    }
42
}
43