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

Validator   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 15
ccs 5
cts 5
cp 1
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 7 1
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