Test Failed
Push — 7.x ( bea7e1...2b11c5 )
by Adrien
08:51
created

SplEnumBacked   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 11
c 1
b 0
f 1
dl 0
loc 46
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __debugInfo() 0 5 1
A __set_state() 0 8 1
A __construct() 0 4 1
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
 * SplEnumBacked gives the ability to emulate and create backed enumeration objects natively in PHP.
18
 *
19
 * @psalm-api
20
 */
21
#[\AllowDynamicProperties]
22
abstract class SplEnumBacked extends SplEnumUnit implements SplBackedEnum
23
{
24
    use SplBackedEnumTrait;
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    protected function __construct()
30
    {
31
        // Value can be undeclare because typed definition can change.
32
        $this->value = &$this->__default;
0 ignored issues
show
Bug Best Practice introduced by
The property value does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
33
    }
34
35
    /**
36
     * Instanciate an exported object.
37
     *
38
     * @param array<mixed,mixed> $properties
39
     *
40
     * @return SplBackedEnum
41
     *
42
     * @codeCoverageIgnore
43
     * @psalm-suppress UnsafeInstantiation
44
     */
45
    #[\ReturnTypeWillChange]
46
    public static function __set_state(array $properties): SplBackedEnum
47
    {
48
        /** @var SplEnumBacked $object */
49
        $object = parent::__set_state($properties);
50
        $object->value = $properties['value'];
0 ignored issues
show
Bug Best Practice introduced by
The property value does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
51
52
        return $object;
53
    }
54
55
    /**
56
     * Dumping object.
57
     *
58
     * @return array<string,string>
59
     *
60
     * @codeCoverageIgnore
61
     */
62
    public function __debugInfo(): array
63
    {
64
        return [
65
            'name' => $this->name,
66
            'value' => $this->value,
67
        ];
68
    }
69
}
70