Remove code duplication

Signed-off-by: Marc Delisle <marc@infomarc.info>
This commit is contained in:
Marc Delisle 2015-02-14 06:12:53 -05:00
parent 6866e39ac0
commit 2a7f1ed42e
3 changed files with 2 additions and 69 deletions

View File

@ -501,7 +501,8 @@ class ConfigFile
{
$c = $_SESSION[$this->_id];
foreach ($this->_cfgUpdateReadMapping as $map_to => $map_from) {
if (PMA_arrayKeyExists($map_to, $c)) {
// if the key $c exists in $map_to
if (PMA_arrayRead($map_to, $c) !== null) {
PMA_arrayWrite($map_to, $c, PMA_arrayRead($map_from, $c));
PMA_arrayRemove($map_from, $c);
}

View File

@ -718,29 +718,6 @@ function PMA_downloadHeader($filename, $mimetype, $length = 0, $no_cache = true)
}
}
/**
* Checks whether element given by $path exists in $array.
* $path is a string describing position of an element in an associative array,
* eg. Servers/1/host refers to $array[Servers][1][host]
*
* @param string $path path in the array
* @param array $array the array
*
* @return mixed array element or $default
*/
function PMA_arrayKeyExists($path, $array)
{
$keys = explode('/', $path);
$value =& $array;
foreach ($keys as $key) {
if (! isset($value[$key])) {
return false;
}
$value =& $value[$key];
}
return true;
}
/**
* Returns value of an element in $array given by $path.
* $path is a string describing position of an element in an associative array,

View File

@ -387,49 +387,4 @@ class PMA_Array_Test extends PHPUnit_Framework_TestCase
PMA_arrayWalkRecursive($second, 'stripslashes', true);
$this->assertEquals($second, $target);
}
/**
* Test for PMA_arrayKeyExists
*
* @param boolean $expected Expected result of the function
* @param string $path Path in the array
* @param array $array The array
*
* @return void
*
* @dataProvider provArrayKeyExists
*/
function testArrayKeyExists($expected, $path, $array)
{
$this->assertEquals($expected, PMA_arrayKeyExists($path, $array));
}
/**
* Data provider for testArrayKeyExists
*
* @return array
*/
function provArrayKeyExists()
{
return array(
array(true, 'k1', array('k1' => array())),
array(true, 'k1/k2', array('k1' => array('k2' => array()))),
array(
true, 'k1/k2', array('k1' => array('k3' => array(), 'k2' => array()))
),
array(
true, 'k1/k2', array('k1' => array('k2' => array('k3' => array())))
),
array(
true,
'k1/k2/k3',
array('k1' => array('k2' => array('k3' => array())))
),
array(false, '', array('k1' => array())),
array(false, 'k1/k2', array('k1' => array())),
array(false, 'k1/k2', array('k1' => array(), 'k2' => array())),
array(false, 'k1/k3', array('k1' => array('k2' => array()))),
array(false, 'k2', array('k1' => array('k2' => array()))),
);
}
}