Passed
Push — master ( b22a88...886da7 )
by Marcel
02:28
created

Validator::validate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace UMA\JsonRpc\Internal;
6
7
use Opis\JsonSchema\Validator as OpisValidator;
8
use stdClass;
9
10
final class Validator
11
{
12
    /**
13
     * @param stdClass|null $schema The schema to check against the given data.
14
     * @param mixed         $data   The data to validate (MUST be decoded JSON data).
15
     *
16
     * @return bool Whether $data conforms to $schema or not
17
     */
18 27
    public static function validate(stdClass $schema, $data): bool
19
    {
20 27
        \assert(false !== \json_encode($data));
21
22 27
        return (new OpisValidator)
23 27
            ->dataValidation($data, $schema)
24 27
            ->isValid();
25
    }
26
}
27