diff --git a/src/Decoder.php b/src/Decoder.php index c10331d46..7241e7e92 100644 --- a/src/Decoder.php +++ b/src/Decoder.php @@ -371,7 +371,7 @@ protected function _getNextToken() default: throw new RuntimeException("Illegal escape sequence '{$chr}'"); } - } elseif($chr == '"') { + } elseif ($chr == '"') { break; } else { $result .= $chr; @@ -457,7 +457,7 @@ public static function decodeUnicodeString($chrs) $utf8 = ''; $strlen_chrs = strlen($chrs); - for($i = 0; $i < $strlen_chrs; $i++) { + for ($i = 0; $i < $strlen_chrs; $i++) { $substr_chrs_c_2 = substr($chrs, $i, 2); $ord_chrs_c = ord($chrs[$i]); @@ -531,7 +531,7 @@ public static function decodeUnicodeString($chrs) protected static function _utf162utf8($utf16) { // Check for mb extension otherwise do by hand. - if( function_exists('mb_convert_encoding') ) { + if (function_exists('mb_convert_encoding')) { return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16'); } diff --git a/src/Encoder.php b/src/Encoder.php index 1b26d4b71..10b4ed81c 100644 --- a/src/Encoder.php +++ b/src/Encoder.php @@ -453,7 +453,7 @@ public static function encodeUnicodeString($value) * Iterate over every character in the string, * escaping with a slash or encoding to UTF-8 where necessary */ - for($i = 0; $i < $strlen_var; $i++) { + for ($i = 0; $i < $strlen_var; $i++) { $ord_var_c = ord($value[$i]); switch (true) { @@ -542,7 +542,7 @@ public static function encodeUnicodeString($value) protected static function _utf82utf16($utf8) { // Check for mb extension otherwise do by hand. - if( function_exists('mb_convert_encoding') ) { + if (function_exists('mb_convert_encoding')) { return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8'); } diff --git a/src/Expr.php b/src/Expr.php index ad73f0844..37360d977 100644 --- a/src/Expr.php +++ b/src/Expr.php @@ -23,13 +23,13 @@ * 'integer' =>9, * 'string' =>'test string', * 'function' => Zend_Json_Expr( - * 'function(){ window.alert("javascript function encoded by Zend_Json") }' + * 'function() { window.alert("javascript function encoded by Zend_Json") }' * ), * ); * * Zend_Json::encode($foo, false, array('enableJsonExprFinder' => true)); * // it will returns json encoded string: - * // {"integer":9,"string":"test string","function":function(){window.alert("javascript function encoded by Zend_Json")}} + * // {"integer":9,"string":"test string","function":function() {window.alert("javascript function encoded by Zend_Json")}} * * * @category Zend diff --git a/src/Json.php b/src/Json.php index c3b7316fa..65b9e74b6 100644 --- a/src/Json.php +++ b/src/Json.php @@ -110,7 +110,7 @@ public static function encode($valueToEncode, $cycleCheck = false, $options = ar // Pre-encoding look for Zend_Json_Expr objects and replacing by tmp ids $javascriptExpressions = array(); - if(isset($options['enableJsonExprFinder']) + if (isset($options['enableJsonExprFinder']) && ($options['enableJsonExprFinder'] == true) ) { $valueToEncode = self::_recursiveJsonExprFinder($valueToEncode, $javascriptExpressions); @@ -129,7 +129,7 @@ public static function encode($valueToEncode, $cycleCheck = false, $options = ar //only do post-processing to revert back the Zend_Json_Expr if any. if (count($javascriptExpressions) > 0) { $count = count($javascriptExpressions); - for($i = 0; $i < $count; $i++) { + for ($i = 0; $i < $count; $i++) { $magicKey = $javascriptExpressions[$i]['magicKey']; $value = $javascriptExpressions[$i]['value']; @@ -347,26 +347,26 @@ public static function prettyPrint($json, $options = array()) $indent = 0; $ind = "\t"; - if(isset($options['indent'])) { + if (isset($options['indent'])) { $ind = $options['indent']; } $inLiteral = false; - foreach($tokens as $token) { - if($token == "") continue; + foreach ($tokens as $token) { + if ($token == "") continue; $prefix = str_repeat($ind, $indent); - if(!$inLiteral && ($token == "{" || $token == "[")) { + if (!$inLiteral && ($token == "{" || $token == "[")) { $indent++; - if($result != "" && $result[strlen($result)-1] == "\n") { + if ($result != "" && $result[strlen($result)-1] == "\n") { $result .= $prefix; } $result .= "$token\n"; - } else if(!$inLiteral && ($token == "}" || $token == "]")) { + } elseif (!$inLiteral && ($token == "}" || $token == "]")) { $indent--; $prefix = str_repeat($ind, $indent); $result .= "\n$prefix$token"; - } else if(!$inLiteral && $token == ",") { + } elseif (!$inLiteral && $token == ",") { $result .= "$token\n"; } else { $result .= ($inLiteral ? '' : $prefix) . $token; diff --git a/src/Server/Server.php b/src/Server/Server.php index e6d5f3eac..ec4516e0f 100644 --- a/src/Server/Server.php +++ b/src/Server/Server.php @@ -508,7 +508,7 @@ protected function _handle() } //Make sure named parameters are passed in correct order - if ( is_string( key( $params ) ) ) { + if (is_string( key( $params ) )) { $callback = $invocable->getCallback(); if ('function' == $callback->getType()) { @@ -522,10 +522,10 @@ protected function _handle() } $orderedParams = array(); - foreach( $reflection->getParameters() as $refParam ) { - if( isset( $params[ $refParam->getName() ] ) ) { + foreach ($reflection->getParameters() as $refParam) { + if (isset( $params[ $refParam->getName() ] )) { $orderedParams[ $refParam->getName() ] = $params[ $refParam->getName() ]; - } elseif( $refParam->isOptional() ) { + } elseif ($refParam->isOptional()) { $orderedParams[ $refParam->getName() ] = null; } else { return $this->fault('Invalid params', Error::ERROR_INVALID_PARAMS); diff --git a/test/JsonTest.php b/test/JsonTest.php index bf3a7fd86..072914ba8 100644 --- a/test/JsonTest.php +++ b/test/JsonTest.php @@ -503,7 +503,7 @@ public function testEncodingObjectWithExprAndInternalEncoder() */ public function testEncodingObjectWithExprAndExtJSON() { - if(!function_exists('json_encode')) { + if (!function_exists('json_encode')) { $this->markTestSkipped('Test only works with ext/json enabled!'); } @@ -543,12 +543,12 @@ public function testEncodingMultipleNestedSwitchingSameNameKeysWithDifferentJSON { $data = array( 0 => array( - "alpha" => new Json\Expr("function(){}"), + "alpha" => new Json\Expr("function() {}"), "beta" => "gamma", ), 1 => array( "alpha" => "gamma", - "beta" => new Json\Expr("function(){}"), + "beta" => new Json\Expr("function() {}"), ), 2 => array( "alpha" => "gamma", @@ -558,7 +558,7 @@ public function testEncodingMultipleNestedSwitchingSameNameKeysWithDifferentJSON $result = Json\Json::encode($data, false, array('enableJsonExprFinder' => true)); $this->assertEquals( - '[{"alpha":function(){},"beta":"gamma"},{"alpha":"gamma","beta":function(){}},{"alpha":"gamma","beta":"gamma"}]', + '[{"alpha":function() {},"beta":"gamma"},{"alpha":"gamma","beta":function() {}},{"alpha":"gamma","beta":"gamma"}]', $result ); } @@ -598,7 +598,7 @@ public function testDisabledJSONExprFinder() $data = array( 0 => array( - "alpha" => new Json\Expr("function(){}"), + "alpha" => new Json\Expr("function() {}"), "beta" => "gamma", ), ); @@ -682,7 +682,7 @@ public function testDecodeUnicodeStringSolarRegression() */ public function testEncodeWithUtf8IsTransformedSolarRegressionEqualsJSONExt() { - if(function_exists('json_encode') == false) { + if (function_exists('json_encode') == false) { $this->markTestSkipped('Test can only be run, when ext/json is installed.'); }