Completed
Push — master ( 4a5c62...dba287 )
by Daniel
03:51
created

Integer8Reader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 0
cbo 2
dl 0
loc 27
ccs 0
cts 7
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A readUnsigned() 0 4 1
A readSigned() 0 9 2
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
 * 8-bit integer (char) reader
14
 *
15
 * @package GravityMedia\Stream\Reader
16
 */
17
class Integer8Reader extends AbstractIntegerReader
18
{
19
    /**
20
     * Read unsigned 8-bit integer (char) 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 8-bit integer (char) 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