Skip to content

Commit 4c697b8

Browse files
refactoring
1 parent 21a8364 commit 4c697b8

File tree

3 files changed

+3
-6
lines changed

3 files changed

+3
-6
lines changed

src/Add.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@
99
* This function uses strict comparison to determine if element exists
1010
*
1111
* @param array $set The collection
12-
* @param mixed $element Element to be added
1312
* @param mixed ...$elements Elements to be added
1413
* @return int The number of items added to the collection
1514
*/
16-
function add(array &$set, $element, ...$elements): int
15+
function add(array &$set, ...$elements): int
1716
{
1817
$added = 0;
19-
array_unshift($elements, $element);
2018
foreach ($elements as $element) {
2119
if (! in_array($element, $set, true)) {
2220
$set[] = $element;

src/Remove.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@
1111
* remove($set, 1, 3) will return 3 (int) and $set will contain [2, 4]
1212
*
1313
* @param array $set The collection
14-
* @param mixed $element Element to be removed
1514
* @param mixed ...$elements Elements to be removed
1615
* @return int The number of removed elements
1716
*/
18-
function remove(array &$set, $element, ...$elements): int
17+
function remove(array &$set, ...$elements): int
1918
{
2019
$removed = 0;
21-
$elements[] = $element;
2220
foreach ($elements as $element) {
2321
foreach (array_keys($set, $element, true) as $index) {
2422
unset($set[$index]);

tests/HasTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace BrenoRoosevelt\Tests;
55

66
use PHPUnit\Framework\TestCase;
7+
use function BrenoRoosevelt\add;
78
use function BrenoRoosevelt\has;
89

910
class HasTest extends TestCase

0 commit comments

Comments
 (0)