Completed
Pull Request — master (#940)
by Asmir
03:00
created

ExpressionPropertyMetadata::serialize()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 25
nc 1
nop 0
dl 0
loc 27
ccs 0
cts 26
cp 0
crap 2
rs 8.8571
c 0
b 0
f 0
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\ExpressionLanguageRequiredException;
24
use JMS\Serializer\Exception\LogicException;
25
26
/**
27
 * @Annotation
28
 * @Target("METHOD")
29
 *
30
 * @author Asmir Mustafic <[email protected]>
31
 */
32
class ExpressionPropertyMetadata extends PropertyMetadata
33
{
34
    /**
35
     * @var string
36
     */
37
    public $expression;
38
39 10
    public function __construct(string $class, string $fieldName, string $expression)
40
    {
41 10
        $this->class = $class;
42 10
        $this->name = $fieldName;
43 10
        $this->expression = $expression;
44 10
        $this->readOnly = true;
45 10
    }
46
47 9
    public function setAccessor(string $type, ?string $getter = null, ?string $setter = null):void
48
    {
49 9
    }
50
51
    public function serialize()
52
    {
53
        return serialize([
54
            $this->sinceVersion,
55
            $this->untilVersion,
56
            $this->groups,
57
            $this->serializedName,
58
            $this->type,
59
            $this->xmlCollection,
60
            $this->xmlCollectionInline,
61
            $this->xmlEntryName,
62
            $this->xmlKeyAttribute,
63
            $this->xmlAttribute,
64
            $this->xmlValue,
65
            $this->xmlNamespace,
66
            $this->xmlKeyValuePairs,
67
            $this->xmlElementCData,
68
            $this->xmlAttributeMap,
69
            $this->maxDepth,
70
            $this->getter,
71
            $this->setter,
72
            $this->inline,
73
            $this->readOnly,
74
            $this->class,
75
            $this->name,
76
            'excludeIf' => $this->excludeIf,
77
            'expression' => $this->expression,
78
        ]);
79
    }
80
81
    public function unserialize($str)
82
    {
83
        $unserialized = unserialize($str);
84
        list(
85
            $this->sinceVersion,
86
            $this->untilVersion,
87
            $this->groups,
88
            $this->serializedName,
89
            $this->type,
90
            $this->xmlCollection,
91
            $this->xmlCollectionInline,
92
            $this->xmlEntryName,
93
            $this->xmlKeyAttribute,
94
            $this->xmlAttribute,
95
            $this->xmlValue,
96
            $this->xmlNamespace,
97
            $this->xmlKeyValuePairs,
98
            $this->xmlElementCData,
99
            $this->xmlAttributeMap,
100
            $this->maxDepth,
101
            $this->getter,
102
            $this->setter,
103
            $this->inline,
104
            $this->readOnly,
105
            $this->class,
106
            $this->name
107
            ) = $unserialized;
108
109
        if (isset($unserialized['excludeIf'])) {
110
            $this->excludeIf = $unserialized['excludeIf'];
111
        }
112
        if (isset($unserialized['expression'])) {
113
            $this->expression = $unserialized['expression'];
114
        }
115
    }
116
}
117