Volume   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 54
ccs 23
cts 23
cp 1
rs 10
wmc 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A checkKeyEncoder() 0 6 2
A exists() 0 3 1
A remove() 0 3 1
A store() 0 6 2
A fullPath() 0 3 1
A get() 0 7 2
A __construct() 0 4 1
1
<?php
2
3
namespace kalanis\UploadPerPartes\Target\Local\DrivingFile\Storage;
4
5
6
use kalanis\UploadPerPartes\Interfaces;
7
use kalanis\UploadPerPartes\Target\Local\DrivingFile;
8
use kalanis\UploadPerPartes\Traits\TLang;
9
use kalanis\UploadPerPartes\UploadException;
10
11
12
/**
13
 * Class Volume
14
 * @package kalanis\UploadPerPartes\Target\Local\DrivingFile\Storage
15
 * Processing info file on disk volume
16
 */
17
class Volume implements Interfaces\IDrivingFile
18
{
19
    use TLang;
20
21
    protected string $keyPrefix;
22
23 8
    public function __construct(string $keyPrefix = '', ?Interfaces\IUppTranslations $lang = null)
24
    {
25 8
        $this->keyPrefix = $keyPrefix;
26 8
        $this->setUppLang($lang);
27 8
    }
28
29 1
    public function exists(string $key): bool
30
    {
31 1
        return is_file($this->fullPath($key));
32
    }
33
34 2
    public function get(string $key): string
35
    {
36 2
        $content = @file_get_contents($this->fullPath($key));
37 2
        if (false === $content) {
38 1
            throw new UploadException($this->getUppLang()->uppDriveFileCannotRead($key));
39
        }
40 1
        return $content;
41
    }
42
43 2
    public function store(string $key, string $data): string
44
    {
45 2
        if (false === @file_put_contents($this->fullPath($key), $data)) {
46 1
            throw new UploadException($this->getUppLang()->uppDriveFileCannotWrite($key));
47
        }
48 1
        return $key;
49
    }
50
51 1
    public function remove(string $key): bool
52
    {
53 1
        return @unlink($this->fullPath($key));
54
    }
55
56
    /**
57
     * @param string $key
58
     * @return string
59
     */
60 3
    protected function fullPath(string $key): string
61
    {
62 3
        return $this->keyPrefix . $key;
63
    }
64
65 3
    public function checkKeyEncoder(DrivingFile\KeyEncoders\AEncoder $encoder): bool
66
    {
67 3
        if (!$encoder instanceof Interfaces\Storages\ForVolume) {
68 1
            throw new UploadException($this->getUppLang()->uppKeyEncoderVariantIsWrong(get_class($encoder)));
69
        }
70 2
        return true;
71
    }
72
}
73