-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ArrayTools + remove value function + update PhpSpec
- Loading branch information
Showing
5 changed files
with
72 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace spec\Nekland\Tools; | ||
|
||
use Nekland\Tools\ArrayTools; | ||
use PhpSpec\ObjectBehavior; | ||
use Prophecy\Argument; | ||
|
||
class ArrayToolsSpec extends ObjectBehavior | ||
{ | ||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType('Nekland\Tools\ArrayTools'); | ||
} | ||
|
||
function it_should_remove_value() | ||
{ | ||
$array = [ | ||
'foo', | ||
'bar', | ||
]; | ||
|
||
ArrayTools::removeValue($array, $array[1]); | ||
|
||
\expect($array)->toBe([$array[0]]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Nekland\Tools; | ||
|
||
class ArrayTools | ||
{ | ||
/** | ||
* Remove a value from the list | ||
* | ||
* @param array $array The array in which we have to remove value | ||
* @param mixed $value The value to remove from the list | ||
*/ | ||
public static function removeValue(array &$array, $value) | ||
{ | ||
$index = \array_search($value, $array); | ||
if (false !== $index) { | ||
unset($array[$index]); | ||
} | ||
} | ||
} |