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

StaticPropertyMetadata::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
ccs 7
cts 7
cp 1
rs 9.4285
cc 1
eloc 6
nc 1
nop 4
crap 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