StringLiteral   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 76
Duplicated Lines 10.53 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 2
dl 8
loc 76
ccs 18
cts 18
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A fromNative() 0 6 1
A __construct() 0 8 2
A toNative() 0 4 1
A sameValueAs() 8 8 2
A isEmpty() 0 4 1
A __toString() 0 4 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 EventStore\ValueObjects\StringLiteral;
3
4
use EventStore\ValueObjects\Exception\InvalidNativeArgumentException;
5
use EventStore\ValueObjects\Util\Util;
6
use EventStore\ValueObjects\ValueObjectInterface;
7
8
class StringLiteral implements ValueObjectInterface
9
{
10
    protected $value;
11
12
    /**
13
     * Returns a StringLiteral object given a PHP native string as parameter.
14
     *
15
     * @param  string        $value
0 ignored issues
show
Bug introduced by
There is no parameter named $value. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
16
     * @return StringLiteral
17
     */
18 1
    public static function fromNative()
19
    {
20 1
        $value = func_get_arg(0);
21
22 1
        return new static($value);
23
    }
24
25
    /**
26
     * Returns a StringLiteral object given a PHP native string as parameter.
27
     *
28
     * @param string $value
29
     */
30 6
    public function __construct($value)
31
    {
32 6
        if (false === \is_string($value)) {
33 1
            throw new InvalidNativeArgumentException($value, array('string'));
34
        }
35
36 5
        $this->value = $value;
37 5
    }
38
39
    /**
40
     * Returns the value of the string
41
     *
42
     * @return string
43
     */
44 32
    public function toNative()
45
    {
46 32
        return $this->value;
47
    }
48
49
    /**
50
     * Tells whether two string literals are equal by comparing their values
51
     *
52
     * @param  ValueObjectInterface $stringLiteral
53
     * @return bool
54
     */
55 2 View Code Duplication
    public function sameValueAs(ValueObjectInterface $stringLiteral)
0 ignored issues
show
Duplication introduced by
This method 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...
56
    {
57 2
        if (false === Util::classEquals($this, $stringLiteral)) {
58 1
            return false;
59
        }
60
61 2
        return $this->toNative() === $stringLiteral->toNative();
62
    }
63
64
    /**
65
     * Tells whether the StringLiteral is empty
66
     *
67
     * @return bool
68
     */
69 1
    public function isEmpty()
70
    {
71 1
        return \strlen($this->toNative()) == 0;
72
    }
73
74
    /**
75
     * Returns the string value itself
76
     *
77
     * @return string
78
     */
79 1
    public function __toString()
80
    {
81 1
        return $this->toNative();
82
    }
83
}
84