From ce9b55d44a06aa1af4fca1374bbe1d38664609d7 Mon Sep 17 00:00:00 2001 From: Donovan Bourlard Date: Thu, 12 Jul 2018 12:15:10 +0200 Subject: [PATCH] Add ArrayTools + remove value function + update PhpSpec --- CHANGELOG.md | 3 +++ README.md | 14 +++++++++++++- composer.json | 11 +++++++++-- spec/Nekland/Tools/ArrayToolsSpec.php | 27 +++++++++++++++++++++++++++ src/ArrayTools.php | 20 ++++++++++++++++++++ 5 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 spec/Nekland/Tools/ArrayToolsSpec.php create mode 100644 src/ArrayTools.php 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 @@ +