FinalStorage::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 7
ccs 3
cts 3
cp 1
crap 1
rs 10
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 19
    public function __construct(
22
        IFinalStorage $storage,
23
        KeyEncoders\AEncoder $keyEncoder
24
    )
25
    {
26 19
        $this->storage = $storage;
27 19
        $this->keyEncoder = $keyEncoder;
28 19
    }
29
30
    /**
31
     * @param Data $data
32
     * @throws UploadException
33
     * @return bool
34
     */
35 1
    public function exists(Data $data): bool
36
    {
37 1
        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 6
    public function store(string $key, $source): bool
47
    {
48 6
        return $this->storage->store($key, $source);
49
    }
50
51
    /**
52
     * @param Data $data
53
     * @throws UploadException
54
     * @return string
55
     */
56 6
    public function findName(Data $data): string
57
    {
58 6
        return $this->storage->findName($this->keyEncoder->toPath($data));
59
    }
60
}
61