StringLiteral::sameValueAs()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 8
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 2
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