Browse Source

#196 refactored method name

tags/2.0.0-beta
Antonio Ramirez 12 years ago
parent
commit
5da62fab3a
  1. 8
      framework/helpers/base/ArrayHelper.php
  2. 4
      tests/unit/framework/helpers/ArrayHelperTest.php

8
framework/helpers/base/ArrayHelper.php

@ -95,7 +95,7 @@ class ArrayHelper
* ~~~
* // $array = array('type'=>'A', 'options'=>array(1,2));
* // working with array
* $type = \yii\helpers\ArrayHelper::popValue($array, 'type');
* $type = \yii\helpers\ArrayHelper::remove($array, 'type');
* // $array content
* // $array = array('options'=>array(1,2));
* ~~~
@ -105,10 +105,10 @@ class ArrayHelper
* @param mixed $default the default value to be returned if the specified key does not exist
* @return mixed|null the value of the element if found, default value otherwise
*/
public static function popValue(&$array, $key, $default = null)
public static function remove(&$array, $key, $default = null)
{
if (is_array($array)) {
$value = static::getValue($array, $key, $default);
if (is_array($array) && (isset($array[$key]) || array_key_exists($key, $array))) {
$value = $array[$key];
unset($array[$key]);
return $value;
}

4
tests/unit/framework/helpers/ArrayHelperTest.php

@ -12,10 +12,10 @@ class ArrayHelperTest extends \yii\test\TestCase
}
public function testPopvalue()
public function testRemove()
{
$array = array('name' => 'b', 'age' => 3);
$name = ArrayHelper::popValue($array, 'name');
$name = ArrayHelper::remove($array, 'name');
$this->assertEquals($name, 'b');
$this->assertEquals($array, array('age' => 3));

Loading…
Cancel
Save