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

Composite   A

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
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