Passed
Pull Request — master (#1366)
by Asmir
09:41
created

StaticPropertyMetadata   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 27.78%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 51
ccs 10
cts 36
cp 0.2778
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 3 1
A setAccessor() 0 2 1
A __construct() 0 8 1
A serializeToArray() 0 5 1
A unserializeFromArray() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace JMS\Serializer\Metadata;
6
7
class StaticPropertyMetadata extends PropertyMetadata
8
{
9
    /**
10
     * @var mixed
11 43
     */
12
    private $value;
13 43
14 43
    /**
15 43
     * StaticPropertyMetadata constructor.
16 43
     *
17 43
     * @param mixed $fieldValue
18 43
     * @param array $groups
19 43
     */
20
    public function __construct(string $className, string $fieldName, $fieldValue, array $groups = [])
21 15
    {
22
        $this->class = $className;
23 15
        $this->name = $fieldName;
24
        $this->serializedName = $fieldName;
25
        $this->value = $fieldValue;
26
        $this->readOnly = true;
27
        $this->groups = $groups;
28
    }
29
30
    /**
31
     * @return mixed
32
     */
33
    public function getValue()
34
    {
35
        return $this->value;
36
    }
37
38
    public function setAccessor(string $type, ?string $getter = null, ?string $setter = null): void
39
    {
40
    }
41
42
    protected function serializeToArray(): array
43
    {
44
        return [
45
            $this->value,
46
            parent::serializeToArray(),
47
        ];
48
    }
49
50
    protected function unserializeFromArray(array $data): void
51
    {
52
        [
53
            $this->value,
54
            $parentData,
55
        ] = $data;
56
57
        parent::unserializeFromArray($parentData);
58
    }
59
}
60