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

CharReader::readSigned()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

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 9
ccs 0
cts 5
cp 0
rs 9.6666
cc 2
eloc 5
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
 * Char (8-bit integer) reader
14
 *
15
 * @package GravityMedia\Stream\Reader
16
 */
17
class CharReader extends AbstractIntegerReader
18
{
19
    /**
20
     * Read unsigned char (8-bit integer) data from the stream
21
     *
22
     * @return int
23
     */
24
    protected function readUnsigned()
25
    {
26
        return ord($this->getStream()->read(1));
27
    }
28
29
    /**
30
     * Read signed char (8-bit integer) data from the stream
31
     *
32
     * @return int
33
     */
34
    protected function readSigned()
35
    {
36
        $value = ord($this->getStream()->read(1));
37
        if ($value > 127) {
38
            return -$value - 2 * (128 - $value);
39
        }
40
41
        return $value;
42
    }
43
}
44