AbstractAdapter   A
last analyzed

↳ Parent: Project

Coupling/Cohesion

Components 1
Dependencies 0

Complexity

Total Complexity 5

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 65
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setPathPrefix() 0 11 2
A getPathPrefix() 0 4 1
A applyPathPrefix() 0 4 1
A removePathPrefix() 0 4 1
1
<?php
2
3
namespace League\Flysystem\Adapter;
4
5
use League\Flysystem\AdapterInterface;
6
7
abstract class AbstractAdapter implements AdapterInterface
8
{
9
    /**
10
     * @var string path prefix
11
     */
12
    protected $pathPrefix;
13
14
    /**
15
     * @var string
16
     */
17
    protected $pathSeparator = '/';
18
19
    /**
20
     * Set the path prefix.
21
     *
22
     * @param string $prefix
23
     *
24
     * @return void
25
     */
26 171
    public function setPathPrefix($prefix)
27
    {
28 171
        $prefix = (string) $prefix;
29
30 171
        if ($prefix === '') {
31 6
            $this->pathPrefix = null;
32 6
            return;
33
        }
34
35 171
        $this->pathPrefix = rtrim($prefix, '\\/') . $this->pathSeparator;
36 171
    }
37
38
    /**
39
     * Get the path prefix.
40
     *
41
     * @return string path prefix
42
     */
43 162
    public function getPathPrefix()
44
    {
45 162
        return $this->pathPrefix;
46
    }
47
48
    /**
49
     * Prefix a path.
50
     *
51
     * @param string $path
52
     *
53
     * @return string prefixed path
54
     */
55 156
    public function applyPathPrefix($path)
56
    {
57 156
        return $this->getPathPrefix() . ltrim($path, '\\/');
58
    }
59
60
    /**
61
     * Remove a path prefix.
62
     *
63
     * @param string $path
64
     *
65
     * @return string path without the prefix
66
     */
67 69
    public function removePathPrefix($path)
68
    {
69 69
        return substr($path, strlen($this->getPathPrefix()));
70
    }
71
}
72