Completed
Push — master ( 81b9ba...d5ded5 )
by Asmir
04:29
created

StaticPropertyMetadata   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 14.75%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 81
c 0
b 0
f 0
ccs 9
cts 61
cp 0.1475
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getValue() 0 4 1
A setValue() 0 4 1
A setAccessor() 0 3 1
B serialize() 0 26 1
B unserialize() 0 26 1
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 36
    public function __construct($className, $fieldName, $fieldValue, array $groups = array())
26
    {
27 36
        $this->class = $className;
28 36
        $this->name = $fieldName;
29 36
        $this->value = $fieldValue;
30 36
        $this->readOnly = true;
31 36
        $this->groups = $groups;
32 36
    }
33
34 15
    public function getValue($obj)
35
    {
36 15
        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->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