public static function castFromJson(JsonParseException $exception): self
    {
        $details = $exception->getDetails();
        $message = $exception->getMessage();
        $line = $details['line'] ?? -1;
        $snippet = null;

        if (preg_match("/^Parse error on line (\\d+):\n(.+)\n.+\n(.+)$/", $message, $matches)) {
            $line = (int) $matches[1];
            $snippet = $matches[2];
            $message = $matches[3];
        }

        $trailingComma = false;
        $pos = mb_strpos($message, ' - It appears you have an extra trailing comma');
        if ($pos > 0) {
            $message = mb_substr($message, 0, $pos);
            $trailingComma = true;
        }

        if (mb_strpos($message, 'Expected') === 0 && $trailingComma) {
            $message = 'It appears you have an extra trailing comma';
        }

        $message = 'JSON parsing failed: ' . $message;

        return new static($message, $line, $snippet, JSON_ERROR_SYNTAX);
    }
public static function castFromJson(JsonParseException $exception): self
    {
        $details = $exception->getDetails();
        $message = $exception->getMessage();
        $line = $details['line'] ?? -1;
        $snippet = null;

        if (preg_match("/^Parse error on line (\\d+):\n(.+)\n.+\n(.+)$/", $message, $matches)) {
            $line = (int) $matches[1];
            $snippet = $matches[2];
            $message = $matches[3];
        }

        $trailingComma = false;
        $pos = mb_strpos($message, ' - It appears you have an extra trailing comma');
        if ($pos > 0) {
            $message = mb_substr($message, 0, $pos);
            $trailingComma = true;
        }

        if (mb_strpos($message, 'Expected') === 0 && $trailingComma) {
            $message = 'It appears you have an extra trailing comma';
        }

        $message = 'JSON parsing failed: ' . $message;

        return new static($message, $line, $snippet, JSON_ERROR_SYNTAX);
    }
public static function castFromJson ( JsonParseException $ exception ) : self { $ details = $ exception -> getDetails ( ) ; $ message = $ exception -> getMessage ( ) ; $ line = $ details [ 'line' ] ?? - 1 ; $ snippet = null ; if ( preg_match ( "/^Parse error on line (\\d+):\n(.+)\n.+\n(.+)$/" , $ message , $ matches ) ) { $ line = ( int ) $ matches [ 1 ] ; $ snippet = $ matches [ 2 ] ; $ message = $ matches [ 3 ] ; } $ trailingComma = false ; $ pos = mb_strpos ( $ message , ' - It appears you have an extra trailing comma' ) ; if ( $ pos > 0 ) { $ message = mb_substr ( $ message , 0 , $ pos ) ; $ trailingComma = true ; } if ( mb_strpos ( $ message , 'Expected' ) === 0 && $ trailingComma ) { $ message = 'It appears you have an extra trailing comma' ; } $ message = 'JSON parsing failed: ' . $ message ; return new static ( $ message , $ line , $ snippet , JSON_ERROR_SYNTAX ) ; }
Casts JsonLint ParseException to ours.
Casts JsonLint ParseException to ours .