Passed
Push — master ( a995e6...3e1dc9 )
by Asmir
47s queued 11s
created

PropertyMetadata::__serialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 0
cts 0
cp 0
crap 2
rs 10
c 1
b 1
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Metadata;
6
7
/**
8
 * Base class for property metadata.
9
 *
10
 * This class is intended to be extended to add your application specific
11
 * properties, and flags.
12
 *
13
 * @author Johannes M. Schmitt <[email protected]>
14
 */
15
class PropertyMetadata implements \Serializable
16
{
17
    /**
18
     * @var string
19
     */
20
    public $class;
21
22
    /**
23
     * @var string
24
     */
25
    public $name;
26
27 3
    public function __construct(string $class, string $name)
28
    {
29 3
        $this->class = $class;
30 3
        $this->name = $name;
31 3
    }
32
33
    /**
34
     * @return string
35
     *
36
     * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
37
     * @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint
38
     * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.UselessReturnAnnotation
39
     */
40 1
    public function serialize()
41
    {
42 1
        return serialize($this->__serialize());
43 1
    }
44 1
45
    /**
46
     * @param string $str
47
     *
48
     * @return void
49
     *
50
     * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
51
     * @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint
52
     * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.UselessReturnAnnotation
53
     */
54
    public function unserialize($str)
55
    {
56
        $this->__unserialize((array) unserialize((string) $str));
57 1
    }
58
59 1
    /**
60 1
     * @return array<string>
61
     */
62
    public function __serialize(): array
63
    {
64
        return [
65
            $this->class,
66
            $this->name,
67
        ];
68
    }
69
70
    /**
71
     * @param array<string> $data
72
     */
73
    public function __unserialize(array $data): void
74
    {
75
        [$this->class, $this->name] = $data;
76
    }
77
}
78