Merge pull request #14871 from owncloud/use-proper-error-type

Use proper error type and clean-up code
This commit is contained in:
Thomas Müller 2015-03-13 23:30:49 +01:00
commit 918b86a5bc
1 changed files with 24 additions and 18 deletions

View File

@ -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) === '<?php') {
$string = substr($string, 5);
@ -56,7 +61,7 @@ class ArrayParser {
* @param string $string
* @return string
*/
function stripAssignAndReturn($string) {
private function stripAssignAndReturn($string) {
$string = trim($string);
if (substr($string, 0, 6) === 'return') {
$string = substr($string, 6);
@ -71,7 +76,7 @@ class ArrayParser {
* @param string $string
* @return array|bool|int|null|string
*/
function parse($string) {
private function parse($string) {
$string = trim($string);
$string = trim($string, ';');
switch ($this->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;