Completed
Push — master ( 3263c7...ec87e5 )
by Nelson
04:25
created

Composite::getUrl()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace DocumentStorage\Adapter\Storage;
4
5
use DocumentStorage\Exception\DocumentNotFoundException;
6
use DocumentStorage\Storage;
7
8
class Composite implements Storage
9
{
10
    /** @var Storage[] */
11
    private $storages;
12
13
    public function __construct(Storage ...$storages)
14
    {
15
        $this->storages = $storages;
16
    }
17
18
    public function store(string $pathOrBody, string $docName, string $oldDocName = '') : string
19
    {
20
        foreach ($this->storages as $storage) {
21
            $storage->store($pathOrBody, $docName, $oldDocName);
22
        }
23
24
        return $docName;
25
    }
26
27
    public function retrieve(string $docName) : string
28
    {
29
        foreach ($this->storages as $storage) {
30
            return $storage->retrieve($docName);
31
        }
32
33
        throw new DocumentNotFoundException(sprintf('Could not retrieve [%s]', $docName));
34
    }
35
36
    public function getUrl(string $docName) : string
37
    {
38
        foreach ($this->storages as $storage) {
39
            return $storage->getUrl($docName);
40
        }
41
42
        throw new DocumentNotFoundException(sprintf('Could not retrieve [%s]', $docName));
43
    }
44
}
45