Passed
Push — master ( 2ddebf...84c74c )
by Petr
09:17 queued 01:35
created

ALocalVolume   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

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
    /** @var string */
23
    protected $startPath = '';
24
    /** @var ArrayPath */
25
    protected $pathLib = null;
26
27 12
    public function __construct(?IMiTranslations $lang = null)
28
    {
29 12
        $this->setMiLang($lang);
30 12
        $this->pathLib = new ArrayPath();
31 12
    }
32
33 10
    public function canUse($source): bool
34
    {
35 10
        if (!$this->hasDependencies()) {
36 1
            return false;
37
        }
38 9
        if (!is_string($source)) {
39 3
            return false;
40
        }
41 7
        $path = realpath($source);
42 7
        if (false === $path) {
43 3
            return false;
44
        }
45 4
        $this->startPath = $path;
46 4
        return true;
47
    }
48
49
    abstract protected function hasDependencies(): bool;
50
51
    /**
52
     * @param string[] $path
53
     * @throws PathsException
54
     * @return string
55
     */
56 6
    protected function pathOnVolume(array $path): string
57
    {
58 6
        return $this->startPath . DIRECTORY_SEPARATOR . $this->pathLib->setArray($path)->getString();
59
    }
60
}
61