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

Str   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 10
c 1
b 0
f 0
dl 0
loc 26
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A isJson() 0 17 4
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
}