AbstractAdapter   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 80
ccs 22
cts 22
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setPathPrefix() 0 10 3
A getPathPrefix() 0 4 1
A applyPathPrefix() 0 14 4
A removePathPrefix() 0 10 2
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 self
25
     */
26 159
    public function setPathPrefix($prefix)
27
    {
28 159
        $is_empty = empty($prefix);
29
30 159
        if ( ! $is_empty) {
31 159
            $prefix = rtrim($prefix, $this->pathSeparator) . $this->pathSeparator;
32 159
        }
33
34 159
        $this->pathPrefix = $is_empty ? null : $prefix;
35 159
    }
36
37
    /**
38
     * Get the path prefix.
39
     *
40
     * @return string path prefix
41
     */
42 150
    public function getPathPrefix()
43
    {
44 150
        return $this->pathPrefix;
45
    }
46
47
    /**
48
     * Prefix a path.
49
     *
50
     * @param string $path
51
     *
52
     * @return string prefixed path
53
     */
54 144
    public function applyPathPrefix($path)
55
    {
56 144
        $path = ltrim($path, '\\/');
57
58 144
        if (strlen($path) === 0) {
59 12
            return $this->getPathPrefix() ?: '';
60
        }
61
62 135
        if ($prefix = $this->getPathPrefix()) {
63 132
            $path = $prefix . $path;
64 132
        }
65
66 135
        return $path;
67
    }
68
69
    /**
70
     * Remove a path prefix.
71
     *
72
     * @param string $path
73
     *
74
     * @return string path without the prefix
75
     */
76 60
    public function removePathPrefix($path)
77
    {
78 60
        $pathPrefix = $this->getPathPrefix();
79
80 60
        if ($pathPrefix === null) {
81 3
            return $path;
82
        }
83
84 57
        return substr($path, strlen($pathPrefix));
85
    }
86
}
87