Passed
Push — master ( a995e6...3e1dc9 )
by Asmir
01:25 queued 49s
created

PropertyMetadata   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 11
dl 0
loc 61
ccs 11
cts 11
cp 1
rs 10
c 2
b 1
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A unserialize() 0 3 1
A serialize() 0 3 1
A __serialize() 0 5 1
A __unserialize() 0 3 1
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