Completed
Pull Request — master (#787)
by
unknown
03:32
created

StaticPropertyMetadata::setValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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