ALocalVolume   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 17
c 1
b 0
f 0
dl 0
loc 40
rs 10
ccs 15
cts 15
cp 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A canUse() 0 14 4
A pathOnVolume() 0 3 1
1
<?php
2
3
namespace kalanis\kw_mime\Check;
4
5
6
use kalanis\kw_mime\Interfaces\IMimeChecks;
7
use kalanis\kw_mime\Interfaces\IMiTranslations;
8
use kalanis\kw_paths\ArrayPath;
9
use kalanis\kw_paths\PathsException;
10
11
12
/**
13
 * Class ALocalVolume
14
 * @package kalanis\kw_mime\Check
15
 * System libraries to get the mime type - works over local volume, not on remote files
16
 */
17
abstract class ALocalVolume implements IMimeChecks
18
{
19
    use Traits\TCheckCalls;
20
    use Traits\TResult;
21
22
    protected string $startPath = '';
23
    protected ArrayPath $pathLib;
24
25 12
    public function __construct(?IMiTranslations $lang = null)
26
    {
27 12
        $this->setMiLang($lang);
28 12
        $this->pathLib = new ArrayPath();
29
    }
30
31 10
    public function canUse($source): bool
32
    {
33 10
        if (!$this->hasDependencies()) {
34 1
            return false;
35
        }
36 9
        if (!is_string($source)) {
37 3
            return false;
38
        }
39 7
        $path = realpath($source);
40 7
        if (false === $path) {
41 3
            return false;
42
        }
43 4
        $this->startPath = $path;
44 4
        return true;
45
    }
46
47
    abstract protected function hasDependencies(): bool;
48
49
    /**
50
     * @param string[] $path
51
     * @throws PathsException
52
     * @return string
53
     */
54 6
    protected function pathOnVolume(array $path): string
55
    {
56 6
        return $this->startPath . DIRECTORY_SEPARATOR . $this->pathLib->setArray($path)->getString();
57
    }
58
}
59