Completed
Push — master ( 44b0be...4a5c62 )
by Daniel
02:13
created

AbstractIntegerReader::read()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 0
cts 4
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 6
1
<?php
2
/**
3
 * This file is part of the stream package
4
 *
5
 * @author Daniel Schröder <[email protected]>
6
 */
7
8
namespace GravityMedia\Stream\Reader;
9
10
use GravityMedia\Stream\Exception;
11
12
/**
13
 * Abstract integer reader
14
 *
15
 * @package GravityMedia\Stream\Reader
16
 */
17
abstract class AbstractIntegerReader extends AbstractReader
18
{
19
    /**
20
     * @var boolean
21
     */
22
    protected $signed;
23
24
    /**
25
     * Is signed
26
     *
27
     * @return boolean
28
     */
29
    public function isSigned()
30
    {
31
        if (null === $this->signed) {
32
            return false;
33
        }
34
35
        return $this->signed;
36
    }
37
38
    /**
39
     * Set signed
40
     *
41
     * @param boolean $signed
42
     *
43
     * @return $this
44
     */
45
    public function setSigned($signed)
46
    {
47
        $this->signed = $signed;
48
        return $this;
49
    }
50
51
    /**
52
     * Read integer data from the stream
53
     *
54
     * @return int
55
     */
56
    public function read()
57
    {
58
        if ($this->isSigned()) {
59
            return $this->readSigned();
60
        }
61
62
        return $this->readUnsigned();
63
    }
64
65
    /**
66
     * Read unsigned integer data from the stream
67
     *
68
     * @return int
69
     */
70
    abstract protected function readUnsigned();
71
72
    /**
73
     * Read signed integer data from the stream
74
     *
75
     * @return int
76
     */
77
    abstract protected function readSigned();
78
}
79