Code Duplication    Length = 40-50 lines in 4 locations

src/ValueObject/BodyLength.php 1 location

@@ 7-56 (lines=50) @@
4
use DjThossi\Ensure\EnsureIsGreaterThanTrait;
5
use DjThossi\Ensure\EnsureIsIntegerTrait;
6
7
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

src/ValueObject/Concurrency.php 1 location

@@ 7-56 (lines=50) @@
4
use DjThossi\Ensure\EnsureIsGreaterThanTrait;
5
use DjThossi\Ensure\EnsureIsIntegerTrait;
6
7
class Concurrency
8
{
9
    use EnsureIsIntegerTrait;
10
    use EnsureIsGreaterThanTrait;
11
12
    const CONCURRENCY_IS_NOT_AN_INTEGER = 1;
13
    const CONCURRENCY_IS_TOO_SMALL = 2;
14
15
    /**
16
     * @var int
17
     */
18
    private $concurrency;
19
20
    /**
21
     * @param int $concurrency
22
     */
23
    public function __construct($concurrency)
24
    {
25
        $this->ensureConcurrency($concurrency);
26
27
        $this->concurrency = $concurrency;
28
    }
29
30
    /**
31
     * @return int
32
     */
33
    public function asInteger()
34
    {
35
        return $this->concurrency;
36
    }
37
38
    /**
39
     * @param mixed $concurrency
40
     */
41
    private function ensureConcurrency($concurrency)
42
    {
43
        $this->ensureIsInteger(
44
            'Concurrency',
45
            $concurrency,
46
            self::CONCURRENCY_IS_NOT_AN_INTEGER
47
        );
48
49
        $this->ensureIsGreaterThan(
50
            'Concurrency',
51
            0,
52
            $concurrency,
53
            self::CONCURRENCY_IS_TOO_SMALL
54
        );
55
    }
56
}
57

src/ValueObject/RequestTimeout.php 1 location

@@ 7-56 (lines=50) @@
4
use DjThossi\Ensure\EnsureIsGreaterThanTrait;
5
use DjThossi\Ensure\EnsureIsIntegerTrait;
6
7
class RequestTimeout
8
{
9
    use EnsureIsIntegerTrait;
10
    use EnsureIsGreaterThanTrait;
11
12
    const IN_SECONDS_IS_NOT_AN_INTEGER = 1;
13
    const IN_SECONDS_IS_TOO_SMALL = 2;
14
15
    /**
16
     * @var int
17
     */
18
    private $inSeconds;
19
20
    /**
21
     * @param int $inSeconds
22
     */
23
    public function __construct($inSeconds)
24
    {
25
        $this->ensureInSeconds($inSeconds);
26
27
        $this->inSeconds = $inSeconds;
28
    }
29
30
    /**
31
     * @return int
32
     */
33
    public function inSeconds()
34
    {
35
        return $this->inSeconds;
36
    }
37
38
    /**
39
     * @param mixed $inSeconds
40
     */
41
    private function ensureInSeconds($inSeconds)
42
    {
43
        $this->ensureIsInteger(
44
            'InSeconds',
45
            $inSeconds,
46
            self::IN_SECONDS_IS_NOT_AN_INTEGER
47
        );
48
49
        $this->ensureIsGreaterThan(
50
            'InSeconds',
51
            -1,
52
            $inSeconds,
53
            self::IN_SECONDS_IS_TOO_SMALL
54
        );
55
    }
56
}
57

src/ValueObject/TimeToFirstByte.php 1 location

@@ 7-46 (lines=40) @@
4
use DjThossi\Ensure\EnsureIsGreaterThanTrait;
5
use DjThossi\Ensure\EnsureIsIntegerTrait;
6
7
class TimeToFirstByte
8
{
9
    use EnsureIsIntegerTrait;
10
    use EnsureIsGreaterThanTrait;
11
12
    const IN_MILLISECONDS_IS_NOT_AN_INTEGER = 1;
13
    const IN_MILLISECONDS_IS_TOO_SMALL = 2;
14
15
    /**
16
     * @var int
17
     */
18
    private $inMilliseconds;
19
20
    /**
21
     * @param int $inMilliseconds
22
     */
23
    public function __construct($inMilliseconds)
24
    {
25
        $this->ensureInMilliseconds($inMilliseconds);
26
27
        $this->inMilliseconds = $inMilliseconds;
28
    }
29
30
    /**
31
     * @return int
32
     */
33
    public function inMilliSeconds()
34
    {
35
        return $this->inMilliseconds;
36
    }
37
38
    /**
39
     * @param mixed $inMilliseconds
40
     */
41
    private function ensureInMilliseconds($inMilliseconds)
42
    {
43
        $this->ensureIsInteger('InMilliseconds', $inMilliseconds, self::IN_MILLISECONDS_IS_NOT_AN_INTEGER);
44
        $this->ensureIsGreaterThan('InMilliseconds', 0, $inMilliseconds, self::IN_MILLISECONDS_IS_TOO_SMALL);
45
    }
46
}
47