Completed
Push — master ( 931447...ecc26b )
by Asmir
11s
created

VirtualPropertyMetadata   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Test Coverage

Coverage 17.46%

Importance

Changes 0
Metric Value
dl 0
loc 79
ccs 11
cts 63
cp 0.1746
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 2
A setAccessor() 0 2 1
B unserialize() 0 30 2
B serialize() 0 26 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
class VirtualPropertyMetadata extends PropertyMetadata
24
{
25 43
    public function __construct($class, $methodName)
26
    {
27 43
        if (0 === strpos($methodName, 'get')) {
28 43
            $fieldName = lcfirst(substr($methodName, 3));
29
        } else {
30 9
            $fieldName = $methodName;
31
        }
32
33 43
        $this->class = $class;
34 43
        $this->name = $fieldName;
35 43
        $this->getter = $methodName;
36 43
        $this->readOnly = true;
37 43
    }
38
39 41
    public function setAccessor($type, $getter = null, $setter = null)
40
    {
41 41
    }
42
43
    public function serialize()
44
    {
45
        return serialize([
46
            $this->sinceVersion,
47
            $this->untilVersion,
48
            $this->groups,
49
            $this->serializedName,
50
            $this->type,
51
            $this->xmlCollection,
52
            $this->xmlCollectionInline,
53
            $this->xmlEntryName,
54
            $this->xmlKeyAttribute,
55
            $this->xmlAttribute,
56
            $this->xmlValue,
57
            $this->xmlNamespace,
58
            $this->xmlKeyValuePairs,
59
            $this->xmlElementCData,
60
            $this->xmlAttributeMap,
61
            $this->maxDepth,
62
            $this->getter,
63
            $this->setter,
64
            $this->inline,
65
            $this->readOnly,
66
            $this->class,
67
            $this->name,
68
            'excludeIf' => $this->excludeIf,
69
        ]);
70
    }
71
72
    public function unserialize($str)
73
    {
74
        $unserialized = unserialize($str);
75
        list(
76
            $this->sinceVersion,
77
            $this->untilVersion,
78
            $this->groups,
79
            $this->serializedName,
80
            $this->type,
81
            $this->xmlCollection,
82
            $this->xmlCollectionInline,
83
            $this->xmlEntryName,
84
            $this->xmlKeyAttribute,
85
            $this->xmlAttribute,
86
            $this->xmlValue,
87
            $this->xmlNamespace,
88
            $this->xmlKeyValuePairs,
89
            $this->xmlElementCData,
90
            $this->xmlAttributeMap,
91
            $this->maxDepth,
92
            $this->getter,
93
            $this->setter,
94
            $this->inline,
95
            $this->readOnly,
96
            $this->class,
97
            $this->name
98
            ) = $unserialized;
99
100
        if (isset($unserialized['excludeIf'])) {
101
            $this->excludeIf = $unserialized['excludeIf'];
102
        }
103
    }
104
}
105