SplBool::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

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