Byte   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 28
loc 28
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A read() 16 16 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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