Skip to content

Commit 9035369

Browse files
committed
bump min version, rename family methods, replace FromArray with allowing constructor to accept arrays
1 parent cf12ed2 commit 9035369

File tree

6 files changed

+572
-407
lines changed

6 files changed

+572
-407
lines changed

.travis.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
language: php
22

33
php:
4-
- '7.1'
5-
- '7.2'
6-
- '7.3'
74
- '7.4'
5+
- '8.0'
6+
- '8.1'
7+
- '8.2'
88

99
install:
1010
- composer install
1111
- composer require satooshi/php-coveralls:~1.0@stable
12-
12+
1313
before_script:
14-
- mkdir -p build/logs
14+
- mkdir -p build/logs
1515

16-
script:
16+
script:
1717
- vendor/bin/phpunit --coverage-clover build/logs/clover.xml
1818

1919
after_success:

README.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Sets require a min PHP version of 7.1.
1111

1212
* [Installation](#installation)
1313
* [**Basic usage:**](#basic-usage)
14-
* [Creating a Set](#creating)
14+
* [Creating a Set](#creating-a-set)
1515
* [Adding values](#adding-values)
1616
* [Removing values](#removing-values)
1717
* [Testing if a value is present](#testing-if-a-value-is-present)
@@ -20,16 +20,15 @@ Sets require a min PHP version of 7.1.
2020
* [As a traditional Array](#as-a-traditional-array)
2121
* [Using `entries()`](#using-entries)
2222
* [Using `each`](#using-eachcallback-args)
23-
* [Using `values`](#using-values)
2423
* [**Set operations**](#set-operations)
2524
* [Union](#union)
2625
* [Difference](#difference)
2726
* [Symmetric difference](#symmetric-difference)
2827
* [Intersect](#intersect)
2928
* [Subsets](#subsets)
3029
* [**Set family operations**](#set-family-operations)
31-
* [UnionOfArray](#union-of-array)
32-
* [IntersectionOfArray](#intersection-of-array)
30+
* [Family Union](#union-of-a-family-of-sets)
31+
* [Family Intersection](#intersection-of-a-family-of-sets)
3332

3433
## Installation
3534
You can download the latest release via the releases link on this page.
@@ -64,9 +63,12 @@ Sets cannot contain duplicate values, and values are stored in insertion order.
6463
$set = new Set(1, 2, 1, 3, 2);
6564
````
6665

67-
If you have an array of elements, you can create a set containing those values.
66+
If you have an array of elements, you can either pass in the array directly, or splat the array.
6867
```php
69-
$set = Set::FromArray([1, 2, 3]);
68+
$set = new Set([1, 2, 1, 3, 2]);
69+
70+
$array = [1, 2, 1, 3, 2];
71+
$set = new Set(...$array);
7072
```
7173

7274
#### Adding values
@@ -166,6 +168,8 @@ foreach ($set as $val) {
166168
}
167169
````
168170

171+
Or if you want, you can iterate `$set->values()` instead.
172+
169173
#### Using `entries()`
170174
The `entries()` method returns an [ArrayIterator](http://php.net/manual/en/class.arrayiterator.php) object.
171175
````php
@@ -265,33 +269,30 @@ and welcome.
265269

266270
#### Union of a Family of Sets
267271

268-
At present the family of sets needs to be in an array of `Set`s.
269-
Then we pass that array of sets to `Set::UnionOfArray()`.
270-
For example:
272+
At present the family of sets needs to be in an array of `Set` objects:
271273
```php
272-
$set1 = Set(1,2,3);
273-
$set2 = Set(3,4,5);
274-
$set_family = [ $set1, $set2 ];
275-
$set_union = Set::UnionOfArray($set_family);
274+
$set1 = Set(1, 2, 3);
275+
$set2 = Set(3, 4, 5);
276+
$set2 = Set(5, 1, 6);
277+
278+
$set_union = Set::familyUnion([$set1, $set2]); // [1, 2, 3, 4, 5, 6]
276279
```
277280

278281
#### Intersection of a Family of Sets
279282

280-
As with `UnionOfArray`, the family of sets needs to be in an array of `Set`s.
281-
Then pass that array of sets to `Set::IntersectionOfArray()`.
282-
For example:
283+
As with `familyUnion`, the family of sets needs to be in an array of `Set` objects:
283284
```php
284285
$set1 = Set(1,2,3);
285286
$set2 = Set(3,4,5);
286287
$set_family = [ $set1, $set2 ];
287-
$set_intersection = Set::IntersectionOfArray($set_family);
288+
$set_intersection = Set::familyIntersection($set_family);
288289
```
289290

290291
Note that, contrary to Set Theory, the result of
291292
taking the intersection of an empty array results
292293
in an empty array. (In Set Theory the intersection
293294
of an empty family is undefined as it would be the
294-
'set of all sets'.)
295+
['set of all sets'](https://en.wikipedia.org/wiki/Universal_set).)
295296

296297
### Contributing
297298
Contributions and changes welcome! Just open an issue or submit a PR :muscle:

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
}
1010
],
1111
"require": {
12-
"php": ">=7.1"
12+
"php": ">=7.4"
1313
},
1414
"require-dev": {
15-
"phpunit/phpunit": ">=7.0"
15+
"phpunit/phpunit": "^9.6.8"
1616
},
1717
"autoload": {
1818
"psr-4": {
@@ -21,7 +21,7 @@
2121
},
2222
"autoload-dev": {
2323
"psr-4": {
24-
"PhpSets\\Test\\": "test/"
24+
"PhpSets\\Test\\": "tests/"
2525
}
2626
}
2727
}

0 commit comments

Comments
 (0)