ChainStorage::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the PHP Translation package.
5
 *
6
 * (c) PHP Translation team <[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
namespace Translation\Common\Storage;
13
14
use Symfony\Component\Translation\MessageCatalogueInterface;
15
use Translation\Common\Model\MessageInterface;
16
17
/**
18
 * This storage allow you to deal with several storages at once.
19
 */
20
class ChainStorage implements StorageInterface
21
{
22
    private $storages = [];
23
24
    /**
25
     * @param StorageInterface[] $storages
26
     */
27 8
    public function __construct(array $storages = [])
28
    {
29 8
        $this->storages = $storages;
30 8
    }
31
32 8
    public function addStorage(StorageInterface $storage): void
33
    {
34 8
        $this->storages[] = $storage;
35 8
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 3
    public function get(string $locale, string $domain, string $key): ?MessageInterface
41
    {
42 3
        foreach ($this->storages as $storage) {
43 3
            if (null !== $message = $storage->get($locale, $domain, $key)) {
44 2
                return $message;
45
            }
46
        }
47
48 1
        return null;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 1
    public function create(MessageInterface $message): void
55
    {
56 1
        foreach ($this->storages as $storage) {
57 1
            $storage->create($message);
58
        }
59 1
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 1
    public function update(MessageInterface $message): void
65
    {
66 1
        foreach ($this->storages as $storage) {
67 1
            $storage->update($message);
68
        }
69 1
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74 1
    public function delete(string $locale, string $domain, string $key): void
75
    {
76 1
        foreach ($this->storages as $storage) {
77 1
            $storage->delete($locale, $domain, $key);
78
        }
79 1
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84 1
    public function export(MessageCatalogueInterface $catalogue, array $options = []): void
85
    {
86 1
        foreach ($this->storages as $storage) {
87 1
            $storage->export($catalogue, $options);
88
        }
89 1
    }
90
91
    /**
92
     * {@inheritdoc}
93
     */
94 1
    public function import(MessageCatalogueInterface $catalogue, array $options = []): void
95
    {
96 1
        foreach ($this->storages as $storage) {
97 1
            $storage->import($catalogue, $options);
98
        }
99 1
    }
100
}
101