Gateway::removePathPrefix()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
namespace tinymeng\uploads\Connector;
3
4
/**
5
 * 所有第三方上传类必须继承的抽象类
6
 */
7
abstract class Gateway implements GatewayInterface
8
{
9
    /**
10
     * 配置信息
11
     *
12
     * @var
13
     */
14
    protected $config;
15
16
    /**
17
     * @var string|null path prefix
18
     */
19
    protected $pathPrefix;
20
21
    /**
22
     * @var string
23
     */
24
    protected $pathSeparator = '/';
25
    /**
26
     * @var 
27
     */
28
    protected $client;
29
30
31
    /**
32
     * Gateway constructor.
33
     * @param null $config
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $config is correct as it would always require null to be passed?
Loading history...
34
     * @throws \Exception
35
     */
36
    public function __construct($config = null)
37
    {
38
        if (!$config) {
0 ignored issues
show
introduced by
$config is of type null, thus it always evaluated to false.
Loading history...
39
            throw new \Exception('传入的配置不能为空');
40
        }
41
        $this->config    = $config;
42
    }
43
44
    /**
45
     * Set the path prefix.
46
     * @param string $prefix
47
     * @return void
48
     */
49
    public function setPathPrefix($prefix)
50
    {
51
        $prefix = (string) $prefix;
52
53
        if ($prefix === '') {
54
            $this->pathPrefix = null;
55
            return;
56
        }
57
58
        $this->pathPrefix = rtrim($prefix, '\\/') . $this->pathSeparator;
59
    }
60
61
    /**
62
     * Get the path prefix.
63
     * @return string|null path prefix or null if pathPrefix is empty
64
     */
65
    public function getPathPrefix()
66
    {
67
        return $this->pathPrefix;
68
    }
69
70
    /**
71
     * Prefix a path.
72
     * @param string $path
73
     * @return string prefixed path
74
     */
75
    public function applyPathPrefix($path)
76
    {
77
        return $this->getPathPrefix() . ltrim($path, '\\/');
78
    }
79
80
    /**
81
     * Remove a path prefix.
82
     * @param string $path
83
     * @return string path without the prefix
84
     */
85
    public function removePathPrefix($path)
86
    {
87
        return substr($path, strlen($this->getPathPrefix()));
0 ignored issues
show
Bug introduced by
It seems like $this->getPathPrefix() can also be of type null; however, parameter $string of strlen() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

87
        return substr($path, strlen(/** @scrutinizer ignore-type */ $this->getPathPrefix()));
Loading history...
88
    }
89
90
91
}
92