Fix misleading param name in FormatJson::encode signature
authorOri Livneh <ori@wikimedia.org>
Fri, 23 Nov 2012 21:51:15 +0000 (13:51 -0800)
committerOri Livneh <ori@wikimedia.org>
Fri, 23 Nov 2012 21:51:15 +0000 (13:51 -0800)
As the FIXME notes, $isHtml has nothing to do with HTML; it simply controls
whether the resultant JSON should be formatted for readability by inserting
whitespace as appropriate.

Change-Id: I90d46d6624d683f18a39c98500bd71bbd0ca3800

includes/json/FormatJson.php

index f67700c..75da5c7 100644 (file)
@@ -31,21 +31,16 @@ class FormatJson {
         * Returns the JSON representation of a value.
         *
         * @param $value Mixed: the value being encoded. Can be any type except a resource.
-        * @param $isHtml Boolean
-        *
-        * @todo FIXME: "$isHtml" parameter's purpose is not documented. It appears to
-        *        map to a parameter labeled "pretty-print output with indents and
-        *        newlines" in Services_JSON::encode(), which has no string relation
-        *        to HTML output.
+        * @param $pretty Boolean: If true, adds non-significant whitespace to improve readability.
         *
         * @return string
         */
-       public static function encode( $value, $isHtml = false ) {
-               if ( !function_exists( 'json_encode' ) || ( $isHtml && version_compare( PHP_VERSION, '5.4.0', '<' ) ) ) {
+       public static function encode( $value, $pretty = false ) {
+               if ( !function_exists( 'json_encode' ) || ( $pretty && version_compare( PHP_VERSION, '5.4.0', '<' ) ) ) {
                        $json = new Services_JSON();
-                       return $json->encode( $value, $isHtml );
+                       return $json->encode( $value, $pretty );
                } else {
-                       return json_encode( $value, $isHtml ? JSON_PRETTY_PRINT : 0 );
+                       return json_encode( $value, $pretty ? JSON_PRETTY_PRINT : 0 );
                }
        }