-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSplBool.php
84 lines (73 loc) · 1.98 KB
/
SplBool.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
* Part of SplTypes package.
*
* (c) Adrien Loyant <donald_duck@team-df.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Ducks\Component\SplTypes;
/**
* The SplBool class is used to enforce strong typing of the bool type.
*
* @extends SplEnum<bool>
* @implements SplBackedEnum<bool>
*
* @property-read mixed $value
* @property-read string $name
*
* @psalm-api
* @psalm-suppress MissingDependency
* @psalm-suppress UndefinedClass
*/
class SplBool extends SplEnum implements SplBackedEnum, SplEnumSingletonable
{
/** @use SplBackedEnumTrait<bool> */
use SplBackedEnumTrait;
/** @use SplEnumBackedTrait<bool> */
use SplEnumBackedTrait;
/**
* @var bool
*
* @psalm-suppress InvalidClassConstantType
*/
// phpcs:ignore Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase
protected const __default = self::false;
/**
* Value of enum instance
*
* @var bool
*/
protected bool $value;
/**
* @var bool
*/
// phpcs:ignore Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase
public const false = false;
/**
* @var bool
*/
// phpcs:ignore Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase
public const true = true;
/**
* {@inheritdoc}
*
* @param bool $initial_value
*
* @SuppressWarnings(PHPMD.CamelCaseParameterName)
* @SuppressWarnings(PHPMD.CamelCaseVariableName)
*/
public function __construct(bool $initial_value = self::__default)
{
parent::__construct($initial_value);
/** @psalm-suppress UnsupportedPropertyReferenceUsage */
$this->value = &$this->__default;
$this->name = $this->value ? 'true' : 'false';
}
final public function &__invoke(): bool
{
return $this->__default;
}
}