Passed
Push — v3.0 ( 9a8f5f...786023 )
by Raza
01:59
created

Str::isJson()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 17
rs 9.9666
cc 4
nc 4
nop 1
1
<?php
2
3
namespace Srmklive\PayPal\Services;
4
5
use GuzzleHttp\Utils;
6
7
class Str extends \Illuminate\Support\Str
8
{
9
    /**
10
     * Determine if a given value is valid JSON.
11
     *
12
     * @param  mixed  $value
13
     *
14
     * @return bool
15
     */
16
    public static function isJson($value): bool
17
    {
18
        if (! is_string($value)) {
19
            return false;
20
        }
21
22
        if (function_exists('json_validate')) {
23
            return json_validate($value, 512);
24
        }
25
26
        try {
27
            Utils::jsonDecode($value, true, 512, 4194304);
28
        } catch (\JsonException) {
29
            return false;
30
        }
31
32
        return true;
33
    }
34
}