Conditions | 8 |
Paths | 5 |
Total Lines | 26 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 12 |
CRAP Score | 8.0291 |
Changes | 4 | ||
Bugs | 2 | Features | 0 |
1 | <?php |
||
3757 | 42 | public static function is_json(string $str, bool $only_array_or_object_results_are_valid = true): bool |
|
3758 | { |
||
3759 | 42 | if ($str === '') { |
|
3760 | 4 | return false; |
|
3761 | } |
||
3762 | |||
3763 | 40 | if (self::$SUPPORT['json'] === false) { |
|
3764 | throw new \RuntimeException('ext-json: is not installed'); |
||
3765 | } |
||
3766 | |||
3767 | 40 | $jsonOrNull = self::json_decode($str); |
|
3768 | 40 | if ($jsonOrNull === null && \strtoupper($str) !== 'NULL') { |
|
3769 | 18 | return false; |
|
3770 | } |
||
3771 | |||
3772 | if ( |
||
3773 | 24 | $only_array_or_object_results_are_valid |
|
3774 | && |
||
3775 | 24 | !\is_object($jsonOrNull) |
|
3776 | && |
||
3777 | 24 | !\is_array($jsonOrNull) |
|
3778 | ) { |
||
3779 | 5 | return false; |
|
3780 | } |
||
3781 | |||
3782 | 19 | return \json_last_error() === \JSON_ERROR_NONE; |
|
3783 | } |
||
13694 |