BodyLength::asInteger()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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