Check   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 52
rs 10
ccs 12
cts 12
cp 1
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isAbsoluteWindowsPath() 0 3 3
A isStream() 0 3 1
A isAbsolutePath() 0 13 4
1
<?php
2
/**
3
 * This file is part of camino.
4
 *
5
 * (c) Sebastian Feldmann <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace SebastianFeldmann\Camino;
11
12
/**
13
 * Class Util
14
 *
15
 * @package SebastianFeldmann\Camino
16
 */
17
abstract class Check
18
{
19
    /**
20
     * Is given path absolute?
21
     *
22
     * @param  string $path
23
     * @return bool
24
     */
25 6
    public static function isAbsolutePath(string $path) : bool
26
    {
27
        // path already absolute?
28 6
        if (substr($path, 0, 1) === '/') {
29 1
            return true;
30
        }
31 5
        if (self::isStream($path)) {
32 1
            return true;
33
        }
34 4
        if (self::isAbsoluteWindowsPath($path)) {
35 2
            return true;
36
        }
37 2
        return false;
38
    }
39
40
    /**
41
     * Is given path a stream reference?
42
     *
43
     * @param string $path
44
     * @return bool
45
     */
46 5
    public static function isStream(string $path): bool
47
    {
48 5
        return strpos($path, '://') !== false;
49
    }
50
51
    /**
52
     * Is given path an absolute windows path?
53
     *
54
     * matches the following on Windows:
55
     *  - \\NetworkComputer\Path
56
     *  - \\.\D:
57
     *  - \\.\c:
58
     *  - C:\Windows
59
     *  - C:\windows
60
     *  - C:/windows
61
     *  - c:/windows
62
     *
63
     * @param  string $path
64
     * @return bool
65
     */
66 4
    public static function isAbsoluteWindowsPath(string $path) : bool
67
    {
68 4
        return ($path[0] === '\\' || (strlen($path) >= 3 && preg_match('#^[A-Z]\:[/\\\]#i', substr($path, 0, 3))));
69
    }
70
}
71