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

Utils   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 10
lcom 0
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isJsonString() 0 7 2
A isHttpSource() 0 10 3
A objectify() 0 4 2
A removeDir() 0 8 3
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