CpeJsonValidator::validate_json()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
cc 3
eloc 16
nc 3
nop 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
}