Completed
Pull Request — develop (#2)
by Sebastian
02:16
created

HeaderKey   A

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 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
1 ignored issue
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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