Volume   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 47
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 47
ccs 22
cts 22
cp 1
rs 10
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A exists() 0 3 1
A getNameSeparator() 0 3 1
A findName() 0 14 3
A fullPath() 0 3 1
A __construct() 0 4 1
A store() 0 4 1
1
<?php
2
3
namespace kalanis\UploadPerPartes\Target\Local\FinalStorage\Storage;
4
5
6
use kalanis\kw_paths\Stuff;
7
use kalanis\UploadPerPartes\Interfaces\IFinalStorage;
8
use kalanis\UploadPerPartes\Interfaces\IUppTranslations;
9
use kalanis\UploadPerPartes\Traits\TLang;
10
11
12
/**
13
 * Class Files
14
 * @package kalanis\UploadPerPartes\Target\Local\FinalStorage\Storage
15
 * Where to store data on target destination - storage is local volume
16
 */
17
class Volume implements IFinalStorage
18
{
19
    use TLang;
20
21
    protected string $pathPrefix = '';
22
23 4
    public function __construct(string $pathPrefix = '', IUppTranslations $lang = null)
24
    {
25 4
        $this->pathPrefix = $pathPrefix;
26 4
        $this->setUppLang($lang);
27 4
    }
28
29 1
    public function exists(string $key): bool
30
    {
31 1
        return @file_exists($this->fullPath($key));
32
    }
33
34 1
    public function store(string $key, $data): bool
35
    {
36 1
        @rewind($data);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for rewind(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

36
        /** @scrutinizer ignore-unhandled */ @rewind($data);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
37 1
        return false !== @file_put_contents($this->fullPath($key), $data);
38
    }
39
40 1
    public function findName(string $key): string
41
    {
42 1
        if (!$this->exists($key)) {
43 1
            return $key;
44
        }
45
46 1
        $name = Stuff::fileBase($key);
47 1
        $suffix = Stuff::fileExt($key);
48
49 1
        $i = 0;
50 1
        while ($this->exists($name . $this->getNameSeparator() . strval($i) . '.' . $suffix)) {
51 1
            $i++;
52
        }
53 1
        return $name . $this->getNameSeparator() . strval($i) . '.' . $suffix;
54
    }
55
56 1
    protected function fullPath(string $key): string
57
    {
58 1
        return $this->pathPrefix . $key;
59
    }
60
61 1
    protected function getNameSeparator(): string
62
    {
63 1
        return '__';
64
    }
65
}
66