Permalink
Browse files

Updating `util\Set::merge()` to accept only two parameters.

  • Loading branch information...
1 parent fcadfd7 commit a9136eb330f48a165cc0ec93e738a678fd490c47 @nateabele nateabele committed Feb 13, 2010
Showing with 12 additions and 9 deletions.
  1. +5 −5 libraries/lithium/tests/cases/util/SetTest.php
  2. +7 −4 libraries/lithium/util/Set.php
@@ -893,8 +893,8 @@ public function testMerge() {
$result = Set::merge('foo', 'bar');
$this->assertIdentical($result, array('foo', 'bar'));
- $result = Set::merge('foo', array('user' => 'bob', 'no-bar'), 'bar');
- $this->assertIdentical($result, array('foo', 'user' => 'bob', 'no-bar', 'bar'));
+ $result = Set::merge('foo', array('user' => 'bob', 'no-bar'));
+ $this->assertIdentical($result, array('foo', 'user' => 'bob', 'no-bar'));
$a = array('foo', 'foo2');
$b = array('bar', 'bar2');
@@ -939,11 +939,11 @@ public function testMerge() {
'ice-cream',
'chocolate'
);
- $this->assertIdentical(Set::merge($a, $b, $c), $expected);
+ $this->assertIdentical($expected, Set::merge(Set::merge($a, $b), $c));
- $this->assertIdentical(Set::merge($a, $b, array(), $c), $expected);
+ $this->assertIdentical($expected, Set::merge(Set::merge($a, $b), Set::merge(array(), $c)));
- $result = Set::merge($a, $b, $c);
+ $result = Set::merge($a, Set::merge($b, $c));
$this->assertIdentical($expected, $result);
$a = array('Tree', 'CounterCache',
@@ -606,7 +606,7 @@ public static function matches($conditions, $data = array(), $i = null, $length
}
/**
- * This function can be thought of as a hybrid between PHP's `array_merge()`
+ * This method can be thought of as a hybrid between PHP's `array_merge()`
* and `array_merge_recursive()`. The difference to the two is that if an
* array key contains another array then the function behaves recursive
* (unlike `array_merge()`) but does not do if for keys containing strings
@@ -616,12 +616,15 @@ public static function matches($conditions, $data = array(), $i = null, $length
*
* @return array Merged array of all passed params.
*/
- public static function merge() {
- $args = func_get_args();
+ public static function merge($arr1, $arr2 = null) {
+ $args = array($arr1, $arr2);
- if (empty($args[0])) {
+ if (empty($arr1) && empty($arr2)) {
return array();
}
+ if (empty($arr1) || empty($arr2)) {
+ return empty($arr1) ? (array) $arr2 : (array) $arr1;
+ }
$result = (array) current($args);
while (($arg = next($args)) !== false) {

0 comments on commit a9136eb

Please sign in to comment.