Passed
Push — main ( 2bc5a4...5ffc2f )
by Vasil
16:31 queued 13:09
created

json_validate()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 6
nc 3
nop 3
dl 0
loc 14
rs 10
c 0
b 0
f 0
1
<?php
2
3
// @codeCoverageIgnoreStart
4
if (! \function_exists('json_validate')) {
5
    function json_validate(string $json, int $depth = 512, int $flags = 0): bool
6
    {
7
        if (0 !== $flags && \JSON_INVALID_UTF8_IGNORE !== $flags) {
8
            throw new \ValueError('json_validate(): Argument #3 ($flags) must be a
9
                valid flag (allowed flags: JSON_INVALID_UTF8_IGNORE)');
10
        }
11
12
        if ($depth <= 0) {
13
            throw new \ValueError('json_validate(): Argument #2 ($depth) must be greater than 0');
14
        }
15
16
        \json_decode($json, null, $depth, $flags);
17
18
        return \JSON_ERROR_NONE === \json_last_error();
19
    }
20
}
21
// @codeCoverageIgnoreEnd
22