Passed
Push — 7.x ( 3ebc9f...4982c4 )
by Adrien
08:52
created

SplTypeTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 64
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __set_state() 0 3 1
A __debugInfo() 0 4 1
A __toString() 0 3 1
A __serialize() 0 4 1
A __unserialize() 0 3 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
namespace Ducks\Component\SplTypes;
13
14
/**
15
 * Trait used for magic
16
 */
17
trait SplTypeTrait
18
{
19
    /**
20
     * Internal enum value.
21
     *
22
     * @var mixed
23
     */
24
    // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore
25
    protected $__default;
26
27
    /**
28
     * Serialize object.
29
     *
30
     * @return array<string,mixed>
31
     */
32
    final public function __serialize(): array
33
    {
34
        return [
35
            '__default' => $this->__default,
36
        ];
37
    }
38
39
    /**
40
     * Unserialize object.
41
     *
42
     * @param array<string,mixed> $data
43
     * @return void
44
     */
45
    final public function __unserialize(array $data): void
46
    {
47
        $this->__default = $data['__default'];
48
    }
49
50
    /**
51
     * Stringify object.
52
     *
53
     * @return string
54
     */
55
    final public function __toString(): string
56
    {
57
        return (string) $this->__default;
58
    }
59
60
    /**
61
     * Export object.
62
     *
63
     * @param array<mixed,mixed> $properties
64
     *
65
     * @return SplType
66
     */
67
    final public static function __set_state(array $properties): object
68
    {
69
        return new static($properties['__default']);
0 ignored issues
show
Unused Code introduced by
The call to Ducks\Component\SplTypes...ypeTrait::__construct() has too many arguments starting with $properties['__default']. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
        return /** @scrutinizer ignore-call */ new static($properties['__default']);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
70
    }
71
72
    /**
73
     * Dumping object.
74
     *
75
     * @return array<string,mixed>
76
     */
77
    final public function __debugInfo(): array
78
    {
79
        return [
80
            '__default' => $this->__default,
81
        ];
82
    }
83
}
84