Completed
Push — master ( 22d7bb...dd90a8 )
by Ori
03:00
created

Utils::removeDir()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace frictionlessdata\datapackage;
4
5
// TODO: refactor to an independenct package (used by both tableschema and datapackage)
6
class Utils
7
{
8
    public static function isJsonString($json)
9
    {
10
        return
11
            is_string($json)
12
            && (strpos(ltrim($json), '{') === 0)
13
        ;
14
    }
15
16
    public static function isHttpSource($source)
17
    {
18
        return
19
            is_string($source)
20
            && (
21
                strpos($source, 'http:') === 0
22
                || strpos($source, 'https:') === 0
23
            )
24
        ;
25
    }
26
27
    public static function objectify($val)
28
    {
29
        return is_object($val) ? $val : json_decode(json_encode($val));
30
    }
31
32
    public static function removeDir($path)
33
    {
34
        $files = glob($path . '/*');
35
        foreach ($files as $file) {
36
            is_dir($file) ? Utils::removeDir($file) : unlink($file);
37
        }
38
        rmdir($path);
39
    }
40
}
41