json.php ➔ is_json()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 3
nc 3
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
if (!function_exists('is_json')) {
3
    /**
4
     * Проверяем является ли переданная строка json-строкой
5
     *
6
     * @param string $string
7
     * @return bool
8
     */
9
    function is_json(string $string): bool
10
    {
11
        $json = json_decode($string);
12
13
        return is_string($string) && (is_object($json) || is_array($json));
14
    }
15
}