Test Failed
Push — master ( e493d7...b1ea68 )
by Petr
11:01
created

FinalStorage   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 43
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A findName() 0 3 1
A store() 0 3 1
A exists() 0 3 1
1
<?php
2
3
namespace kalanis\UploadPerPartes\Target\Local\FinalStorage;
4
5
6
use kalanis\UploadPerPartes\Interfaces\IFinalStorage;
7
use kalanis\UploadPerPartes\Uploader\Data;
8
use kalanis\UploadPerPartes\UploadException;
9
10
11
/**
12
 * Class FinalStorage
13
 * @package kalanis\UploadPerPartes\Target\Local\FinalStorage
14
 * Actions over final storage
15
 */
16
class FinalStorage
17
{
18
    protected IFinalStorage $storage;
19
    protected KeyEncoders\AEncoder $keyEncoder;
20
21
    public function __construct(
22
        IFinalStorage $storage,
23
        KeyEncoders\AEncoder $keyEncoder
24
    )
25
    {
26
        $this->storage = $storage;
27
        $this->keyEncoder = $keyEncoder;
28
    }
29
30
    /**
31
     * @param Data $data
32
     * @throws UploadException
33
     * @return bool
34
     */
35
    public function exists(Data $data): bool
36
    {
37
        return $this->storage->exists($this->keyEncoder->toPath($data));
38
    }
39
40
    /**
41
     * @param string $key
42
     * @param resource $source
43
     * @throws UploadException
44
     * @return bool
45
     */
46
    public function store(string $key, $source): bool
47
    {
48
        return $this->storage->store($key, $source);
49
    }
50
51
    /**
52
     * @param Data $data
53
     * @throws UploadException
54
     * @return string
55
     */
56
    public function findName(Data $data): string
57
    {
58
        return $this->storage->findName($this->keyEncoder->toPath($data));
59
    }
60
}
61