Str   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A read() 14 14 3
A readAligned() 6 6 1

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 Str 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
     * @param  \PhpBinaryReader\BinaryReader $br
12
     * @param  int                           $length
13
     * @return string
14
     * @throws \OutOfBoundsException
15
     * @throws InvalidDataException
16
     */
17 16
    public function read(BinaryReader &$br, $length)
18
    {
19 16
        if (!is_int($length)) {
20 4
            throw new InvalidDataException('The length parameter must be an integer');
21
        }
22
23 12
        if (!$br->canReadBytes($length)) {
24 4
            throw new \OutOfBoundsException('Cannot read string, it exceeds the boundary of the file');
25
        }
26
27 8
        $str = $br->readFromHandle($length);
28
29 8
        return $str;
30
    }
31
32
    /**
33
     * @param  \PhpBinaryReader\BinaryReader $br
34
     * @param  int                           $length
35
     * @return string
36
     */
37 4
    public function readAligned(BinaryReader &$br, $length)
38
    {
39 4
        $br->align();
40
41 4
        return $this->read($br, $length);
42
    }
43
}
44