Composite   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 37
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A store() 0 8 2
A retrieve() 0 8 2
A getUrl() 0 8 2
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