CpeJsonValidator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate_json() 0 23 3
1
<?php
2
3
namespace SA\CpeSdk;
4
5
class CpeJsonValidator
6
{
7
    public function validate_json(
8
        $json,
9
        $schemas_name,
10
        $schemas_path)
11
    {
12
        $retriever    = new JsonSchema\Uri\UriRetriever;
13
        $json_schemas = $retriever->retrieve('file://' . $schemas_path . "/$schemas_name");
14
15
        $refResolver  = new JsonSchema\RefResolver($retriever);
16
        $refResolver->resolve($json_schemas, 'file://' . $schemas_path . "/");
17
18
        $validator    = new JsonSchema\Validator();
19
        $validator->check($json, $json_schemas);
20
21
        if ($validator->isValid())
22
            return false;
23
    
24
        $details = "";
25
        foreach ($validator->getErrors() as $error)
26
            $details .= sprintf("[%s] %s\n", $error['property'], $error['message']);
27
    
28
        return $details;
29
    }
30
}