Check::isStream()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
crap 1
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