Byte::read()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 8

Duplication

Lines 16
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 16
loc 16
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 2
crap 3
1
<?php
2
3
namespace PhpBinaryReader\Type;
4
5
use PhpBinaryReader\BinaryReader;
6
use PhpBinaryReader\Exception\InvalidDataException;
7
8 View Code Duplication
class Byte implements TypeInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
9
{
10
    /**
11
     * Returns an variable number of bytes
12
     *
13
     * @param  \PhpBinaryReader\BinaryReader $br
14
     * @param  int|null                      $length
15
     * @return string
16
     * @throws \OutOfBoundsException
17
     * @throws InvalidDataException
18
     */
19 12
    public function read(BinaryReader &$br, $length = null)
20
    {
21 12
        if (!is_int($length)) {
22 4
            throw new InvalidDataException('The length parameter must be an integer');
23
        }
24
25 8
        $br->align();
26
27 8
        if (!$br->canReadBytes($length)) {
28 4
            throw new \OutOfBoundsException('Cannot read bytes, it exceeds the boundary of the file');
29
        }
30
31 4
        $segment = $br->readFromHandle($length);
32
33 4
        return $segment;
34
    }
35
}
36