Path::getAdapter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace WSW\SimpleUpload\Traits\Upload;
4
5
use League\Flysystem\Adapter\Local;
6
use League\Flysystem\AdapterInterface;
7
8
trait Path
9
{
10
    /**
11
     * @var AdapterInterface
12
     */
13
    private $adapter;
14
15
    /**
16
     * @return AdapterInterface
17
     */
18 3
    public function getAdapter()
19
    {
20 3
        return $this->adapter;
21
    }
22
23
    /**
24
     * @param AdapterInterface $adapter
25
     * @return self
26
     */
27 3
    public function setAdapter(AdapterInterface $adapter)
28
    {
29 3
        $this->adapter = $adapter;
30 3
        return $this;
31
    }
32
33
34
    /**
35
     * @param string $base
36
     * @param string $dir
37
     * @return string
38
     */
39 3
    public function setPathLocal($base, $dir)
40
    {
41 3
        if (DIRECTORY_SEPARATOR === $dir{0}) {
42 2
            return $dir;
43
        }
44
45 1
        return $base . ltrim($dir, DIRECTORY_SEPARATOR);
46
    }
47
48
    /**
49
     * @param string $path
50
     * @return self
51
     */
52 1
    public function setPath($path)
53
    {
54 1
        if ($this->getAdapter() instanceof Local) {
55 1
            $base = $this->getAdapter()->getPathPrefix();
56 1
            $path = $this->setPathLocal($base, $path);
57
        }
58
59 1
        $this->getAdapter()->setPathPrefix($path);
60 1
        return $this;
61
    }
62
63
    /**
64
     * @return string
65
     */
66 3
    public function getPath()
67
    {
68 3
        return $this->getAdapter()->getPathPrefix();
69
    }
70
}
71