Completed
Push — master ( dfd004...b46837 )
by Jitendra
11s
created

Path::isAbsolute()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 3
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 7
rs 9.4285
1
<?php
2
3
namespace Ahc\Phint\Util;
4
5
class Path
6
{
7
    /**
8
     * Platform agnostic absolute path detection.
9
     *
10
     * @param string $path
11
     *
12
     * @return bool
13
     */
14
    public function isAbsolute($path)
15
    {
16
        if (DIRECTORY_SEPARATOR === '\\') {
17
            return strpos($path, ':') === 1;
18
        }
19
20
        return isset($path[0]) && $path[0] === '/';
21
    }
22
23
    public function getRelativePath($fullPath, $basePath)
24
    {
25
        if (strpos($fullPath, $basePath) === 0) {
26
            return substr($fullPath, strlen($basePath));
27
        }
28
29
        // Hmm!
30
        return $fullPath;
31
    }
32
33
    public function ensureDir($dir)
34
    {
35
        if (!\is_dir($dir)) {
36
            \mkdir($dir, 0777, true);
37
        }
38
    }
39
40
    public function getExtension($filePath)
41
    {
42
        return pathinfo($filePath, PATHINFO_EXTENSION);
43
    }
44
45
    public function readAsJson($filePath, $asArray = true)
0 ignored issues
show
Unused Code introduced by
The parameter $asArray is not used and could be removed. ( Ignorable by Annotation )

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

45
    public function readAsJson($filePath, /** @scrutinizer ignore-unused */ $asArray = true)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
46
    {
47
        return json_decode(file_get_contents($filePath), true) ?: [];
48
    }
49
50
    public function writeFile($file, $content, $mode = null)
51
    {
52
        file_put_contents($file, $content, $mode);
53
    }
54
}
55