Commit b0cd7178 authored by Carsten  Rose's avatar Carsten Rose
Browse files

KeyValueStringParser: variables and constants renamed to be more understandable

parent 0b613ec0
......@@ -43,9 +43,11 @@ const ROW_EXACT_1 = "exact_1";
const ROW_EMPTY_IS_OK = "empty_is_ok";
// KeyValueParser
const KEY_VALUE_SINGLE = 'flag';
const KEY_VALUE_PAIR = 'pair';
const IF_VALUE_EMPTY_COPY_KEY = 'if_value_empty_copy_key';
const VALUE_GIVEN = 'value_given';
// FormBuildPlain
const SUBRECORD_COLUMN_WIDTH = 20;
// QFQ Error Codes
const ERROR_UNKNOW_SANATIZE_CLASS = 1001;
......@@ -72,7 +74,7 @@ const ERROR_MISSING_OPEN_DELIMITER = 1021;
const ERROR_RECURSION_TOO_DEEP = 1022;
const ERROR_UNKNOWN_COLUMN = 1023;
const ERROR_CHECKBOXMODE_UNKNOWN = 1024;
const ERROR_ = 1025;
const ERROR_MISSING_SQL1 = 1025;
const ERROR_CHECKBOX_EQUAL = 1026;
const ERROR_MISSING_ITEM_VALUES = 1027;
......
......@@ -85,12 +85,12 @@ class KeyValueStringParser {
* @param string $keyValueString string of key/value pairs
* @param string $keyValueDelimiter
* @param string $listDelimiter
* @param string $keyValueMode
* @param string $valueMode
* @return array associative array indexed by keys
* @throws UserException
*/
public static function parse($keyValueString, $keyValueDelimiter = ":", $listDelimiter = ",", $keyValueMode = KEY_VALUE_PAIR) {
public static function parse($keyValueString, $keyValueDelimiter = ":", $listDelimiter = ",", $valueMode = VALUE_GIVEN) {
if ($keyValueString === "") {
return array();
}
......@@ -123,7 +123,7 @@ class KeyValueStringParser {
$returnValue[$key] = self::removeSourroundingQuotes(trim($keyValueArray[1]));
} else {
// no Value given: "a"
$returnValue[$key] = ($keyValueMode === KEY_VALUE_PAIR) ? "" : $key;
$returnValue[$key] = ($valueMode === VALUE_GIVEN) ? "" : $key;
}
}
......
......@@ -132,7 +132,7 @@ class KeyValueStringParserTest extends \PHPUnit_Framework_TestCase {
}
public function testParseKeyValueSingle() {
$actual = keyValueStringParser::parse('value1,value2', ':', ',', KEY_VALUE_SINGLE);
$actual = keyValueStringParser::parse('value1,value2', ':', ',', IF_VALUE_EMPTY_COPY_KEY);
$expected = [
'value1' => 'value1',
'value2' => 'value2',
......@@ -140,7 +140,7 @@ class KeyValueStringParserTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals($expected, $actual);
$this->assertCount(2, $actual);
$actual = keyValueStringParser::parse('key1:value1,key2:value2', ':', ',', KEY_VALUE_SINGLE);
$actual = keyValueStringParser::parse('key1:value1,key2:value2', ':', ',', IF_VALUE_EMPTY_COPY_KEY);
$expected = [
'key1' => 'value1',
'key2' => 'value2',
......@@ -148,7 +148,7 @@ class KeyValueStringParserTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals($expected, $actual);
$this->assertCount(2, $actual);
$actual = keyValueStringParser::parse('key1:value1,key2:value2', ':', ',', KEY_VALUE_PAIR);
$actual = keyValueStringParser::parse('key1:value1,key2:value2', ':', ',', VALUE_GIVEN);
$expected = [
'key1' => 'value1',
'key2' => 'value2',
......@@ -156,7 +156,7 @@ class KeyValueStringParserTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals($expected, $actual);
$this->assertCount(2, $actual);
$actual = keyValueStringParser::parse('value1,value2', ':', ',', KEY_VALUE_PAIR);
$actual = keyValueStringParser::parse('value1,value2', ':', ',', VALUE_GIVEN);
$expected = [
'value1' => '',
'value2' => '',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment