diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ceab7e..8399fe2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- New `ArrayTools` class helper +- `ArrayTools::removeValue` method to remove a value from given array ## [2.1.0] - 2017-04-23 ### Added diff --git a/README.md b/README.md index f470b45..54e1e65 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ This library provide some tools to help you with your developments. Here is the list of tools it provides: - [StringTools](#stringtools-class) +- [ArrayTools](#arraytools-class) - [EqualableInterface](#equalableinterface) - [DateTimeComparator](#datetimecomparator-class) @@ -91,6 +92,17 @@ StringTools::mb_ucfirst($str, $encoding) : string * `$str` string input * `$encoding` (optional, default "UTF-8") encoding of your input string +### ArrayTools class + +#### ::removeValue + +```php +ArrayTools::removeValue($array, $value) : void +``` + +* `$array` input array passed by reference +* `$value` The value to remove from the $array + ### EqualableInterface Helps you equals on objects on a similar way as [java](http://stackoverflow.com/questions/1643067/whats-the-difference-between-equals-and). @@ -125,4 +137,4 @@ DateTimeComparator::lowest($dateTime1, $dateTime2) : ?\DateTimeInterface ``` * `$dateTime1` The first \DateTimeInterface or null -* `$dateTime2` The second \DateTimeInterface or null +* `$dateTime2` The second \DateTimeInterface or null \ No newline at end of file diff --git a/composer.json b/composer.json index 1c1bdd8..cee6083 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,14 @@ "autoload": { "psr-4": { "Nekland\\Tools\\": "src/" } }, + "require": { + "php": "^5.6 || ^7.0" + }, "require-dev": { - "phpspec/phpspec": "^2.5" - } + "phpspec/phpspec": "^3.2", + "bossa/phpspec2-expect": "^2.3" + }, + "_comment": [ + "PHPSpec is limited to ^3.2 to keep compatibility with PHP5.6" + ] } diff --git a/spec/Nekland/Tools/ArrayToolsSpec.php b/spec/Nekland/Tools/ArrayToolsSpec.php new file mode 100644 index 0000000..f29473b --- /dev/null +++ b/spec/Nekland/Tools/ArrayToolsSpec.php @@ -0,0 +1,27 @@ +shouldHaveType('Nekland\Tools\ArrayTools'); + } + + function it_should_remove_value() + { + $array = [ + 'foo', + 'bar', + ]; + + ArrayTools::removeValue($array, $array[1]); + + \expect($array)->toBe([$array[0]]); + } +} diff --git a/src/ArrayTools.php b/src/ArrayTools.php new file mode 100644 index 0000000..28b6c65 --- /dev/null +++ b/src/ArrayTools.php @@ -0,0 +1,20 @@ +