Passed
Pull Request — master (#1366)
by Asmir
09:41
created

ExpressionPropertyMetadata::serializeToArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 0
cts 5
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace JMS\Serializer\Metadata;
6
7
use JMS\Serializer\Expression\Expression;
8
9
/**
10
 * @Annotation
11
 * @Target("METHOD")
12
 *
13
 * @author Asmir Mustafic <[email protected]>
14
 */
15
#[\Attribute(\Attribute::TARGET_METHOD)]
16
class ExpressionPropertyMetadata extends PropertyMetadata
17
{
18
    /**
19
     * @var string|Expression
20
     */
21
    public $expression;
22
23 12
    /**
24
     * @param string|Expression $expression
25 12
     */
26 12
    public function __construct(string $class, string $fieldName, $expression)
27 12
    {
28 12
        $this->class = $class;
29 12
        $this->name = $fieldName;
30
        $this->expression = $expression;
31 11
        $this->readOnly = true;
32
    }
33 11
34
    public function setAccessor(string $type, ?string $getter = null, ?string $setter = null): void
35
    {
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    protected function serializeToArray(): array
42
    {
43
        return [
44
            $this->expression,
45
            parent::serializeToArray(),
46
        ];
47
    }
48
49
    protected function unserializeFromArray(array $data): void
50
    {
51
        [
52
            $this->expression,
53
            $parentData,
54
        ] = $data;
55
56
        parent::unserializeFromArray($parentData);
57
    }
58
}
59