SerializationContextCollectorChain   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 40
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A add() 0 4 1
A collect() 0 11 2
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\Collector;
15
16
use FiveLab\Component\Resource\Serializer\Context\MutableSerializationContext;
17
use FiveLab\Component\Resource\Serializer\Context\ResourceSerializationContext;
18
19
/**
20
 * Chain collector for collect serialization context.
21
 *
22
 * @author Vitaliy Zhuk <[email protected]>
23
 */
24
class SerializationContextCollectorChain implements SerializationContextCollectorInterface
25
{
26
    /**
27
     * @var \SplQueue|SerializationContextCollectorInterface[]
28
     */
29
    private $collectors;
30
31
    /**
32
     * Constructor.
33
     */
34 1
    public function __construct()
35
    {
36 1
        $this->collectors = new \SplQueue();
37 1
    }
38
39
    /**
40
     * Add the collector to chain
41
     *
42
     * @param SerializationContextCollectorInterface $collector
43
     */
44 1
    public function add(SerializationContextCollectorInterface $collector): void
45
    {
46 1
        $this->collectors->enqueue($collector);
47 1
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 1
    public function collect(): ResourceSerializationContext
53
    {
54 1
        $serializationContext = new MutableSerializationContext([]);
55
56 1
        foreach ($this->collectors as $collector) {
57 1
            $context = $collector->collect();
58 1
            $serializationContext = $serializationContext->merge($context);
59
        }
60
61 1
        return $serializationContext->copy();
62
    }
63
}
64