PathLibrary::normalizerPath()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 7
c 1
b 0
f 0
nc 6
nop 2
dl 0
loc 13
rs 10
1
<?php
2
// +----------------------------------------------------------------------
3
// | date: 2016-11-13
4
// +----------------------------------------------------------------------
5
// | UtilityLibrary.php: 工具库
6
// +----------------------------------------------------------------------
7
// | Author: yangyifan <[email protected]>
8
// +----------------------------------------------------------------------
9
namespace tinymeng\uploads\Helper;
10
class PathLibrary
11
{
12
    /*
13
     * 内部方法, 规整文件路径
14
     * @param  string  $path      文件路径
15
     * @param  string  $isfolder  是否为文件夹
16
     */
17
    public static function normalizerPath($path, $isfolder = False)
18
    {
19
        if (preg_match('/^\//', $path) == 0) {
20
            $path = '/' . $path;
21
        }
22
        if ($isfolder == True) {
23
            if (preg_match('/\/$/', $path) == 0) {
24
                $path = $path . '/';
25
            }
26
        }
27
        // Remove unnecessary slashes.
28
        $path = preg_replace('#/+#', '/', $path);
29
        return $path;
30
    }
31
}