BodyLength   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 50
loc 50
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 1
A asInteger() 4 4 1
A ensureCharsToPreserve() 15 15 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
namespace DjThossi\SmokeTestingPhp\ValueObject;
3
4
use DjThossi\Ensure\EnsureIsGreaterThanTrait;
5
use DjThossi\Ensure\EnsureIsIntegerTrait;
6
7 View Code Duplication
class BodyLength
8
{
9
    use EnsureIsIntegerTrait;
10
    use EnsureIsGreaterThanTrait;
11
12
    const CHARS_TO_PRESERVE_IS_NOT_AN_INTEGER = 1;
13
    const CHARS_TO_PRESERVE_IS_TOO_SMALL = 2;
14
15
    /**
16
     * @var int
17
     */
18
    private $charsToPreserve;
19
20
    /**
21
     * @param int $charsToPreserve
22
     */
23
    public function __construct($charsToPreserve)
24
    {
25
        $this->ensureCharsToPreserve($charsToPreserve);
26
27
        $this->charsToPreserve = $charsToPreserve;
28
    }
29
30
    /**
31
     * @return int
32
     */
33
    public function asInteger()
34
    {
35
        return $this->charsToPreserve;
36
    }
37
38
    /**
39
     * @param mixed $charsToPreserve
40
     */
41
    private function ensureCharsToPreserve($charsToPreserve)
42
    {
43
        $this->ensureIsInteger(
44
            'CharsToPreserve',
45
            $charsToPreserve,
46
            self::CHARS_TO_PRESERVE_IS_NOT_AN_INTEGER
47
        );
48
49
        $this->ensureIsGreaterThan(
50
            'CharsToPreserve',
51
            -1,
52
            $charsToPreserve,
53
            self::CHARS_TO_PRESERVE_IS_TOO_SMALL
54
        );
55
    }
56
}
57