From 7afe09d4f397d431101c36f228c4504e0484f0f5 Mon Sep 17 00:00:00 2001 From: Chad Gray Date: Sun, 13 Jul 2014 08:04:15 -0400 Subject: [PATCH] PHPCS fixes for Zend\Json --- src/Decoder.php | 36 ++++++++++---------------- src/Encoder.php | 68 ++++++++++++++++++++++++------------------------- src/Json.php | 4 ++- 3 files changed, 50 insertions(+), 58 deletions(-) diff --git a/src/Decoder.php b/src/Decoder.php index e064e6fa1..1960b2ac6 100644 --- a/src/Decoder.php +++ b/src/Decoder.php @@ -334,24 +334,17 @@ protected function _decodeArray() return $result; } - /** * Removes whitespace characters from the source input */ protected function _eatWhitespace() { - if (preg_match( - '/([\t\b\f\n\r ])*/s', - $this->source, - $matches, - PREG_OFFSET_CAPTURE, - $this->offset) + if (preg_match('/([\t\b\f\n\r ])*/s', $this->source, $matches, PREG_OFFSET_CAPTURE, $this->offset) && $matches[0][1] == $this->offset) { $this->offset += strlen($matches[0][0]); } } - /** * Retrieves the next token from the source stream * @@ -375,8 +368,8 @@ protected function _getNextToken() switch ($str{$i}) { case '{': - $this->token = self::LBRACE; - break; + $this->token = self::LBRACE; + break; case '}': $this->token = self::RBRACE; break; @@ -392,7 +385,7 @@ protected function _getNextToken() case ':': $this->token = self::COLON; break; - case '"': + case '"': $result = ''; do { $i++; @@ -409,31 +402,31 @@ protected function _getNextToken() } $chr = $str{$i}; switch ($chr) { - case '"' : + case '"': $result .= '"'; break; case '\\': $result .= '\\'; break; - case '/' : + case '/': $result .= '/'; break; - case 'b' : + case 'b': $result .= "\x08"; break; - case 'f' : + case 'f': $result .= "\x0c"; break; - case 'n' : + case 'n': $result .= "\x0a"; break; - case 'r' : + case 'r': $result .= "\x0d"; break; - case 't' : + case 't': $result .= "\x09"; break; - case '\'' : + case '\'': $result .= '\''; break; default: @@ -468,7 +461,7 @@ protected function _getNextToken() if (($i+ 3) < $strLength && substr($str, $start, 4) == "null") { $this->token = self::DATUM; } - $this->tokenValue = NULL; + $this->tokenValue = null; $i += 3; break; } @@ -480,8 +473,7 @@ protected function _getNextToken() $chr = $str{$i}; if ($chr == '-' || $chr == '.' || ($chr >= '0' && $chr <= '9')) { - if (preg_match('/-?([0-9])*(\.[0-9]*)?((e|E)((-|\+)?)[0-9]+)?/s', - $str, $matches, PREG_OFFSET_CAPTURE, $start) && $matches[0][1] == $start) { + if (preg_match('/-?([0-9])*(\.[0-9]*)?((e|E)((-|\+)?)[0-9]+)?/s', $str, $matches, PREG_OFFSET_CAPTURE, $start) && $matches[0][1] == $start) { $datum = $matches[0][0]; if (is_numeric($datum)) { diff --git a/src/Encoder.php b/src/Encoder.php index 0d8d35527..4bd76fb28 100644 --- a/src/Encoder.php +++ b/src/Encoder.php @@ -95,7 +95,6 @@ protected function _encodeValue(&$value) return $this->_encodeDatum($value); } - /** * Encode an object to JSON by encoding each of the public properties * @@ -129,7 +128,7 @@ protected function _encodeObject(&$value) $props = ''; if (method_exists($value, 'toJson')) { - $props =',' . preg_replace("/^\{(.*)\}$/","\\1", $value->toJson()); + $props = ',' . preg_replace("/^\{(.*)\}$/", "\\1", $value->toJson()); } else { if ($value instanceof IteratorAggregate) { $propCollection = $value->getIterator(); @@ -155,7 +154,6 @@ protected function _encodeObject(&$value) . $props . '}'; } - /** * Determine if an object has been serialized already * @@ -171,7 +169,6 @@ protected function _wasVisited(&$value) return false; } - /** * JSON encode an array value * @@ -215,7 +212,6 @@ protected function _encodeArray(&$array) return $result; } - /** * JSON encode a basic data type (string, number, boolean, null) * @@ -241,7 +237,6 @@ protected function _encodeDatum(&$value) return $result; } - /** * JSON encode a string value by escaping characters as necessary * @@ -265,7 +260,6 @@ protected function _encodeString(&$string) return '"' . $string . '"'; } - /** * Encode the constants associated with the ReflectionClass * parameter. The encoding format is based on the class2 format @@ -290,7 +284,6 @@ private static function _encodeConstants(ReflectionClass $cls) return $result . "}"; } - /** * Encode the public methods of the ReflectionClass in the * class2 format @@ -353,7 +346,6 @@ private static function _encodeMethods(ReflectionClass $cls) return $result . "}"; } - /** * Encode the public properties of the ReflectionClass in the class2 * format. @@ -410,7 +402,6 @@ public static function encodeClass($className, $package = '') . self::_encodeVariables($cls) .'});'; } - /** * Encode several classes at once * @@ -471,9 +462,12 @@ public static function encodeUnicodeString($value) case (($ordVarC & 0xF0) == 0xE0): // characters U-00000800 - U-0000FFFF, mask 1110XXXX // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - $char = pack('C*', $ordVarC, - ord($value[$i + 1]), - ord($value[$i + 2])); + $char = pack( + 'C*', + $ordVarC, + ord($value[$i + 1]), + ord($value[$i + 2]) + ); $i += 2; $utf16 = self::_utf82utf16($char); $ascii .= sprintf('\u%04s', bin2hex($utf16)); @@ -482,10 +476,13 @@ public static function encodeUnicodeString($value) case (($ordVarC & 0xF8) == 0xF0): // characters U-00010000 - U-001FFFFF, mask 11110XXX // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - $char = pack('C*', $ordVarC, - ord($value[$i + 1]), - ord($value[$i + 2]), - ord($value[$i + 3])); + $char = pack( + 'C*', + $ordVarC, + ord($value[$i + 1]), + ord($value[$i + 2]), + ord($value[$i + 3]) + ); $i += 3; $utf16 = self::_utf82utf16($char); $ascii .= sprintf('\u%04s', bin2hex($utf16)); @@ -494,11 +491,14 @@ public static function encodeUnicodeString($value) case (($ordVarC & 0xFC) == 0xF8): // characters U-00200000 - U-03FFFFFF, mask 111110XX // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - $char = pack('C*', $ordVarC, - ord($value[$i + 1]), - ord($value[$i + 2]), - ord($value[$i + 3]), - ord($value[$i + 4])); + $char = pack( + 'C*', + $ordVarC, + ord($value[$i + 1]), + ord($value[$i + 2]), + ord($value[$i + 3]), + ord($value[$i + 4]) + ); $i += 4; $utf16 = self::_utf82utf16($char); $ascii .= sprintf('\u%04s', bin2hex($utf16)); @@ -507,12 +507,15 @@ public static function encodeUnicodeString($value) case (($ordVarC & 0xFE) == 0xFC): // characters U-04000000 - U-7FFFFFFF, mask 1111110X // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - $char = pack('C*', $ordVarC, - ord($value[$i + 1]), - ord($value[$i + 2]), - ord($value[$i + 3]), - ord($value[$i + 4]), - ord($value[$i + 5])); + $char = pack( + 'C*', + $ordVarC, + ord($value[$i + 1]), + ord($value[$i + 2]), + ord($value[$i + 3]), + ord($value[$i + 4]), + ord($value[$i + 5]) + ); $i += 5; $utf16 = self::_utf82utf16($char); $ascii .= sprintf('\u%04s', bin2hex($utf16)); @@ -552,17 +555,12 @@ protected static function _utf82utf16($utf8) case 2: // return a UTF-16 character from a 2-byte UTF-8 char // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - return chr(0x07 & (ord($utf8{0}) >> 2)) - . chr((0xC0 & (ord($utf8{0}) << 6)) - | (0x3F & ord($utf8{1}))); + return chr(0x07 & (ord($utf8{0}) >> 2)) . chr((0xC0 & (ord($utf8{0}) << 6)) | (0x3F & ord($utf8{1}))); case 3: // return a UTF-16 character from a 3-byte UTF-8 char // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 - return chr((0xF0 & (ord($utf8{0}) << 4)) - | (0x0F & (ord($utf8{1}) >> 2))) - . chr((0xC0 & (ord($utf8{1}) << 6)) - | (0x7F & ord($utf8{2}))); + return chr((0xF0 & (ord($utf8{0}) << 4)) | (0x0F & (ord($utf8{1}) >> 2))) . chr((0xC0 & (ord($utf8{1}) << 6)) | (0x7F & ord($utf8{2}))); } // ignoring UTF-32 for now, sorry diff --git a/src/Json.php b/src/Json.php index ec74d1994..96fa0780a 100644 --- a/src/Json.php +++ b/src/Json.php @@ -160,7 +160,9 @@ public static function encode($valueToEncode, $cycleCheck = false, $options = ar * @return mixed */ protected static function _recursiveJsonExprFinder( - &$value, array &$javascriptExpressions, $currentKey = null + &$value, + array &$javascriptExpressions, + $currentKey = null ) { if ($value instanceof Expr) { // TODO: Optimize with ascii keys, if performance is bad