TimeToFirstByte   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 1
A inMilliSeconds() 4 4 1
A ensureInMilliseconds() 5 5 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 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