Completed
Push — master ( abf7e9...c7e2cd )
by Kévin
16s
created

ChainDataPersister::supports()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 1
1
<?php
2
3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace ApiPlatform\Core\DataPersister;
15
16
/**
17
 * Chained data persisters.
18
 *
19
 * @author Baptiste Meyer <[email protected]>
20
 */
21
final class ChainDataPersister implements DataPersisterInterface
22
{
23
    private $persisters;
24
25
    /**
26
     * @param DataPersisterInterface[] $persisters
27
     */
28
    public function __construct(array $persisters)
29
    {
30
        $this->persisters = $persisters;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function supports($data): bool
37
    {
38
        foreach ($this->persisters as $persister) {
39
            if ($persister->supports($data)) {
40
                return true;
41
            }
42
        }
43
44
        return false;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function persist($data)
51
    {
52
        foreach ($this->persisters as $persister) {
53
            if ($persister->supports($data)) {
54
                $persister->persist($data);
55
            }
56
        }
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function remove($data)
63
    {
64
        foreach ($this->persisters as $persister) {
65
            if ($persister->supports($data)) {
66
                $persister->remove($data);
67
            }
68
        }
69
    }
70
}
71