Composite::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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