Completed
Push — master ( 576435...3e25f9 )
by Ronaldo
05:23
created

Path::getAdapter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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
    public function getAdapter()
19
    {
20
        return $this->adapter;
21
    }
22
23
    /**
24
     * @param AdapterInterface $adapter
25
     * @return self
26
     */
27
    public function setAdapter(AdapterInterface $adapter)
28
    {
29
        $this->adapter = $adapter;
30
        return $this;
31
    }
32
33
34
    /**
35
     * @param string $base
36
     * @param string $dir
37
     * @return string
38
     */
39
    public function setPathLocal($base, $dir)
40
    {
41
        if (DIRECTORY_SEPARATOR === $dir{0}) {
42
            return $dir;
43
        }
44
45
        return $base . ltrim($dir, DIRECTORY_SEPARATOR);
46
    }
47
48
    /**
49
     * @param string $path
50
     * @return self
51
     */
52
    public function setPath($path)
53
    {
54
        if ($this->getAdapter() instanceof Local) {
55
            $base = $this->getAdapter()->getPathPrefix();
56
            $path =  $this->setPathLocal($base, $path);
57
        }
58
59
        $this->getAdapter()->setPathPrefix($path);
60
        return $this;
61
    }
62
63
    /**
64
     * @return string
65
     */
66
    public function getPath()
67
    {
68
        return $this->getAdapter()->getPathPrefix();
69
    }
70
}
71