MutableSerializationContext   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 45
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 0 8 1
A merge() 0 8 1
A copy() 0 4 1
1
<?php
2
3
declare(strict_types = 1);
4
5
/*
6
 * This file is part of the FiveLab Resource package
7
 *
8
 * (c) FiveLab
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code
12
 */
13
14
namespace FiveLab\Component\Resource\Serializer\Context;
15
16
/**
17
 * The mutable serialization context.
18
 *
19
 * @author Vitaliy Zhuk <[email protected]>
20
 */
21
class MutableSerializationContext extends ResourceSerializationContext
22
{
23
    /**
24
     * Set the new key-value to context
25
     *
26
     * @param string $key
27
     * @param mixed  $value
28
     *
29
     * @return MutableSerializationContext
30
     */
31 1
    public function set(string $key, $value): MutableSerializationContext
32
    {
33 1
        $cloned = clone $this;
34
35 1
        $cloned->payload[$key] = $value;
36
37 1
        return $cloned;
38
    }
39
40
    /**
41
     * Merge serialization context
42
     *
43
     * @param ResourceSerializationContext $context
44
     *
45
     * @return MutableSerializationContext
46
     */
47 2
    public function merge(ResourceSerializationContext $context): MutableSerializationContext
48
    {
49 2
        $cloned = clone $this;
50
51 2
        $cloned->payload = array_merge($cloned->payload, $context->payload);
52
53 2
        return $cloned;
54
    }
55
56
    /**
57
     * Copy context
58
     *
59
     * @return ResourceSerializationContext
60
     */
61 2
    public function copy(): ResourceSerializationContext
62
    {
63 2
        return new ResourceSerializationContext($this->payload);
64
    }
65
}
66