From 4eb118dd33d1981480c86ec55bdb472ddc4f3c4a Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Fri, 13 Mar 2015 13:04:31 +0100 Subject: [PATCH] Use proper error type and clean-up code --- lib/private/arrayparser.php | 42 +++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/lib/private/arrayparser.php b/lib/private/arrayparser.php index 1cf3355d6f..f513d90fdc 100644 --- a/lib/private/arrayparser.php +++ b/lib/private/arrayparser.php @@ -21,6 +21,11 @@ namespace OC; +/** + * Class ArrayParser + * + * @package OC + */ class ArrayParser { const TYPE_NUM = 1; const TYPE_BOOL = 2; @@ -31,7 +36,7 @@ class ArrayParser { * @param string $string * @return array|bool|int|null|string */ - function parsePHP($string) { + public function parsePHP($string) { $string = $this->stripPHPTags($string); $string = $this->stripAssignAndReturn($string); return $this->parse($string); @@ -41,7 +46,7 @@ class ArrayParser { * @param string $string * @return string */ - function stripPHPTags($string) { + private function stripPHPTags($string) { $string = trim($string); if (substr($string, 0, 5) === 'getType($string)) { @@ -91,7 +96,7 @@ class ArrayParser { * @param string $string * @return int */ - function getType($string) { + private function getType($string) { $string = strtolower($string); $first = substr($string, 0, 1); $last = substr($string, -1, 1); @@ -111,7 +116,7 @@ class ArrayParser { * @param string $string * @return string */ - function parseString($string) { + private function parseString($string) { return substr($string, 1, -1); } @@ -119,7 +124,7 @@ class ArrayParser { * @param string $string * @return int */ - function parseNum($string) { + private function parseNum($string) { return intval($string); } @@ -127,7 +132,7 @@ class ArrayParser { * @param string $string * @return bool */ - function parseBool($string) { + private function parseBool($string) { $string = strtolower($string); return $string === 'true'; } @@ -136,12 +141,12 @@ class ArrayParser { * @param string $string * @return array */ - function parseArray($string) { + private function parseArray($string) { $body = substr($string, 5); $body = trim($body); $body = substr($body, 1, -1); $items = $this->splitArray($body); - $result = array(); + $result = []; $lastKey = -1; foreach ($items as $item) { $item = trim($item); @@ -167,15 +172,16 @@ class ArrayParser { /** * @param string $body * @return array + * @throws \UnexpectedValueException */ - function splitArray($body) { - $inSingleQuote = false;//keep track if we are inside quotes + private function splitArray($body) { + $inSingleQuote = false; //keep track if we are inside quotes $inDoubleQuote = false; - $bracketDepth = 0;//keep track if we are inside brackets - $parts = array(); + $bracketDepth = 0; //keep track if we are inside brackets + $parts = []; $start = 0; - $escaped = false;//keep track if we are after an escape character - $skips = array();//keep track of the escape characters we need to remove from the result + $escaped = false; //keep track if we are after an escape character + $skips = []; //keep track of the escape characters we need to remove from the result if (substr($body, -1, 1) !== ',') { $body .= ','; } @@ -206,7 +212,7 @@ class ArrayParser { $bracketDepth++; } elseif ($char === ')') { if ($bracketDepth <= 0) { - throw new UnexpectedValueException(); + throw new \UnexpectedValueException(); } else { $bracketDepth--; } @@ -217,7 +223,7 @@ class ArrayParser { } $parts[] = $part; $start = $i + 1; - $skips = array(); + $skips = []; } } $escaped = false;