Completed
Push — master ( a6fe0f...b0c0c1 )
by Sebastian
02:05
created

HeaderKey   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 1
A asString() 4 4 1
A ensureKey() 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\EnsureIsNotEmptyTrait;
5
use DjThossi\Ensure\EnsureIsStringTrait;
6
7 View Code Duplication
class HeaderKey
8
{
9
    use EnsureIsStringTrait;
10
    use EnsureIsNotEmptyTrait;
11
12
    const KEY_IS_NOT_A_STRING = 1;
13
    const KEY_IS_EMPTY = 2;
14
15
    /**
16
     * @var string
17
     */
18
    private $key;
19
20
    /**
21
     * @param string $key
22
     */
23
    public function __construct($key)
24
    {
25
        $this->ensureKey($key);
26
27
        $this->key = $key;
28
    }
29
30
    /**
31
     * @return string
32
     */
33
    public function asString()
34
    {
35
        return $this->key;
36
    }
37
38
    /**
39
     * @param mixed $key
40
     */
41
    private function ensureKey($key)
42
    {
43
        $this->ensureIsString('Key', $key, self::KEY_IS_NOT_A_STRING);
44
        $this->ensureIsNotEmpty('Key', $key, self::KEY_IS_EMPTY);
45
    }
46
}
47