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