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

MachineFloatingPoint   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 21
c 2
b 0
f 0
dl 0
loc 61
ccs 17
cts 17
cp 1
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A read() 0 6 1
A write() 0 18 4
1
<?php
2
3
namespace SPSS\Sav\Record\Info;
4
5
use SPSS\Buffer;
6
use SPSS\Sav\Record\Info;
7
8
// Available as of PHP 7.2.0.
9
if (! defined('PHP_FLOAT_MAX')) {
10
    define('PHP_FLOAT_MAX', 1.7976931348623e+308);
11
}
12
13
class MachineFloatingPoint extends Info
14
{
15
    const SUBTYPE = 4;
16
17
    /**
18
     * @var double
19
     */
20
    public $sysmis;
21
22
    /**
23
     * @var double
24
     */
25
    public $highest;
26
27
    /**
28
     * @var double
29
     */
30
    public $lowest;
31
32
    /**
33
     * @var int Always set to 8.
34
     */
35
    protected $dataSize = 8;
36
37
    /**
38
     * @var int Always set to 3.
39
     */
40
    protected $dataCount = 3;
41
42
    /**
43
     * @param Buffer $buffer
44
     */
45 7
    public function read(Buffer $buffer)
46
    {
47 7
        parent::read($buffer);
48 7
        $this->sysmis = $buffer->readDouble();
49 7
        $this->highest = $buffer->readDouble();
50 7
        $this->lowest = $buffer->readDouble();
51 7
    }
52
53
    /**
54
     * @param Buffer $buffer
55
     */
56 7
    public function write(Buffer $buffer)
57
    {
58 7
        if (! $this->sysmis) {
59 6
            $this->sysmis = -PHP_FLOAT_MAX;
60
        }
61
62 7
        if (! $this->highest) {
63 6
            $this->highest = PHP_FLOAT_MAX;
64
        }
65
66 7
        if (! $this->lowest) {
67 6
            $this->lowest = -PHP_FLOAT_MAX;
68
        }
69
70 7
        parent::write($buffer);
71 7
        $buffer->writeDouble($this->sysmis);
72 7
        $buffer->writeDouble($this->highest);
73 7
        $buffer->writeDouble($this->lowest);
74 7
    }
75
}
76