Completed
Branch master (7d7b3f)
by Ori
01:38
created

Utils   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

3 Methods

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