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