From 69c427aaa24340ce1c5e2f862c1c6e904aa0317f Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sun, 12 Aug 2018 20:49:41 +0200 Subject: Make reformat_json more readable Signed-off-by: Florian Pritz --- application/service/renderer.php | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/application/service/renderer.php b/application/service/renderer.php index 6f57e7458..2a28f4e48 100644 --- a/application/service/renderer.php +++ b/application/service/renderer.php @@ -158,23 +158,29 @@ class renderer { */ private function reformat_json($lexer, $linecount, $content) { - if ($lexer === "json" && $linecount === 1) { - $decoded_json = json_decode($content); - if ($decoded_json !== null && $decoded_json !== false) { - $pretty_json = json_encode($decoded_json, JSON_PRETTY_PRINT); - if ($pretty_json !== false) { - $content = $pretty_json; - $this->output_cache->render_now( - array( - "error_type" => "alert-info", - "error_message" => "

The file below has been reformated for readability. It may differ from the original.

" - ), - "file/fragments/alert-wide" - ); - } - } + if ($lexer !== "json" || $linecount !== 1) { + return $content; + } + + $decoded_json = json_decode($content); + if ($decoded_json === null || $decoded_json === false) { + return $content; } - return $content; + + $pretty_json = json_encode($decoded_json, JSON_PRETTY_PRINT); + if ($pretty_json === false) { + return $content; + } + + $this->output_cache->render_now( + array( + "error_type" => "alert-info", + "error_message" => "

The file below has been reformated for readability. It may differ from the original.

" + ), + "file/fragments/alert-wide" + ); + + return $pretty_json; } -- cgit v1.2.3-24-g4f1b