|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ValueObjects\StringLiteral; |
|
4
|
|
|
|
|
5
|
|
|
use ValueObjects\Exception\InvalidNativeArgumentException; |
|
6
|
|
|
use ValueObjects\Util\Util; |
|
7
|
|
|
use ValueObjects\ValueObjectInterface; |
|
8
|
|
|
|
|
9
|
|
|
class StringLiteral implements ValueObjectInterface |
|
10
|
|
|
{ |
|
11
|
|
|
protected $value; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Returns a StringLiteral object given a PHP native string as parameter. |
|
15
|
|
|
* |
|
16
|
|
|
* @param string $value |
|
|
|
|
|
|
17
|
|
|
* @return StringLiteral |
|
18
|
|
|
*/ |
|
19
|
1 |
|
public static function fromNative() |
|
20
|
|
|
{ |
|
21
|
1 |
|
$value = func_get_arg(0); |
|
22
|
|
|
|
|
23
|
1 |
|
return new static($value); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Returns a StringLiteral object given a PHP native string as parameter. |
|
28
|
|
|
* |
|
29
|
|
|
* @param string $value |
|
30
|
|
|
*/ |
|
31
|
89 |
|
public function __construct($value) |
|
32
|
|
|
{ |
|
33
|
89 |
|
if (false === \is_string($value)) { |
|
34
|
1 |
|
throw new InvalidNativeArgumentException($value, array('string')); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
88 |
|
$this->value = $value; |
|
38
|
88 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Returns the value of the string |
|
42
|
|
|
* |
|
43
|
|
|
* @return string |
|
44
|
|
|
*/ |
|
45
|
83 |
|
public function toNative() |
|
46
|
|
|
{ |
|
47
|
83 |
|
return $this->value; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Tells whether two string literals are equal by comparing their values |
|
52
|
|
|
* |
|
53
|
|
|
* @param ValueObjectInterface $stringLiteral |
|
54
|
|
|
* @return bool |
|
55
|
|
|
*/ |
|
56
|
46 |
|
public function sameValueAs(ValueObjectInterface $stringLiteral) |
|
57
|
|
|
{ |
|
58
|
46 |
|
if (false === Util::classEquals($this, $stringLiteral)) { |
|
59
|
1 |
|
return false; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
46 |
|
return $this->toNative() === $stringLiteral->toNative(); |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Tells whether the StringLiteral is empty |
|
67
|
|
|
* |
|
68
|
|
|
* @return bool |
|
69
|
|
|
*/ |
|
70
|
10 |
|
public function isEmpty() |
|
71
|
|
|
{ |
|
72
|
10 |
|
return \strlen($this->toNative()) == 0; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Returns the string value itself |
|
77
|
|
|
* |
|
78
|
|
|
* @return string |
|
79
|
|
|
*/ |
|
80
|
23 |
|
public function __toString() |
|
81
|
|
|
{ |
|
82
|
23 |
|
return $this->toNative(); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
function jsonSerialize() |
|
|
|
|
|
|
86
|
|
|
{ |
|
87
|
|
|
return (string) $this; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
|
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
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.