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

Path   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 48
rs 10
c 1
b 0
f 0
wmc 11

6 Methods

Rating   Name   Duplication   Size   Complexity  
A isAbsolute() 0 7 3
A getRelativePath() 0 8 2
A writeFile() 0 3 1
A ensureDir() 0 4 2
A readAsJson() 0 3 2
A getExtension() 0 3 1
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