Completed
Pull Request — master (#934)
by Asmir
04:07 queued 01:19
created

StaticPropertyMetadata   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Test Coverage

Coverage 17.24%

Importance

Changes 0
Metric Value
dl 0
loc 75
ccs 10
cts 58
cp 0.1724
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 3 1
A __construct() 0 8 1
A setAccessor() 0 2 1
B serialize() 0 24 1
B unserialize() 0 25 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright 2016 Johannes M. Schmitt <[email protected]>
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *     http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
21
namespace JMS\Serializer\Metadata;
22
23
use JMS\Serializer\Exception\LogicException;
24
25
class StaticPropertyMetadata extends PropertyMetadata
26
{
27
    private $value;
28
29 43
    public function __construct($className, $fieldName, $fieldValue, array $groups = [])
30
    {
31 43
        $this->class = $className;
32 43
        $this->name = $fieldName;
33 43
        $this->serializedName = $fieldName;
34 43
        $this->value = $fieldValue;
35 43
        $this->readOnly = true;
36 43
        $this->groups = $groups;
37 43
    }
38
39 15
    public function getValue($obj)
40
    {
41 15
        return $this->value;
42
    }
43
44
    public function setAccessor($type, $getter = null, $setter = null)
45
    {
46
    }
47
48
    public function serialize()
49
    {
50
        return serialize([
51
            $this->sinceVersion,
52
            $this->untilVersion,
53
            $this->groups,
54
            $this->serializedName,
55
            $this->type,
56
            $this->xmlCollection,
57
            $this->xmlCollectionInline,
58
            $this->xmlEntryName,
59
            $this->xmlKeyAttribute,
60
            $this->xmlAttribute,
61
            $this->xmlValue,
62
            $this->xmlNamespace,
63
            $this->xmlKeyValuePairs,
64
            $this->xmlElementCData,
65
            $this->getter,
66
            $this->setter,
67
            $this->inline,
68
            $this->readOnly,
69
            $this->class,
70
            $this->name,
71
            $this->value
72
        ]);
73
    }
74
75
    public function unserialize($str)
76
    {
77
        list(
78
            $this->sinceVersion,
79
            $this->untilVersion,
80
            $this->groups,
81
            $this->serializedName,
82
            $this->type,
83
            $this->xmlCollection,
84
            $this->xmlCollectionInline,
85
            $this->xmlEntryName,
86
            $this->xmlKeyAttribute,
87
            $this->xmlAttribute,
88
            $this->xmlValue,
89
            $this->xmlNamespace,
90
            $this->xmlKeyValuePairs,
91
            $this->xmlElementCData,
92
            $this->getter,
93
            $this->setter,
94
            $this->inline,
95
            $this->readOnly,
96
            $this->class,
97
            $this->name,
98
            $this->value
99
            ) = unserialize($str);
100
    }
101
}
102