Skip to content

Commit c4684d2

Browse files
authored
Release/1.8.0 (#19)
* feat: Adds flatten method to remove nested collections and return a single flattened Collection.
1 parent 339b32e commit c4684d2

20 files changed

+273
-130
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,49 @@
11
name: CI
22

33
on:
4-
push:
54
pull_request:
65

76
permissions:
87
contents: read
98

9+
env:
10+
PHP_VERSION: '8.3'
11+
1012
jobs:
1113
auto-review:
1214
name: Auto review
1315
runs-on: ubuntu-latest
1416

1517
steps:
1618
- name: Checkout
17-
uses: actions/checkout@v3
19+
uses: actions/checkout@v4
1820

19-
- name: Use PHP 8.2
21+
- name: Configure PHP
2022
uses: shivammathur/setup-php@v2
2123
with:
22-
php-version: '8.2'
24+
php-version: ${{ env.PHP_VERSION }}
2325

2426
- name: Install dependencies
2527
run: composer update --no-progress --optimize-autoloader
2628

27-
- name: Run phpcs
28-
run: composer phpcs
29-
30-
- name: Run phpmd
31-
run: composer phpmd
29+
- name: Run review
30+
run: composer review
3231

3332
tests:
3433
name: Tests
3534
runs-on: ubuntu-latest
3635

3736
steps:
3837
- name: Checkout
39-
uses: actions/checkout@v3
38+
uses: actions/checkout@v4
4039

41-
- name: Use PHP 8.2
40+
- name: Use PHP ${{ env.PHP_VERSION }}
4241
uses: shivammathur/setup-php@v2
4342
with:
44-
php-version: '8.2'
43+
php-version: ${{ env.PHP_VERSION }}
4544

4645
- name: Install dependencies
4746
run: composer update --no-progress --optimize-autoloader
4847

49-
- name: Run unit tests
50-
env:
51-
XDEBUG_MODE: coverage
52-
run: composer test
53-
54-
- name: Run mutation tests
55-
run: composer test-mutation
48+
- name: Run tests
49+
run: composer tests

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
DOCKER_RUN = docker run --rm -it --net=host -v ${PWD}:/app -w /app gustavofreze/php:8.2
1+
DOCKER_RUN = docker run --rm -it --net=host -v ${PWD}:/app -w /app gustavofreze/php:8.3
22

33
.PHONY: configure test test-file test-no-coverage review show-reports clean
44

@@ -9,7 +9,7 @@ test:
99
@${DOCKER_RUN} composer tests
1010

1111
test-file:
12-
@${DOCKER_RUN} composer tests-file-no-coverage ${FILE}
12+
@${DOCKER_RUN} composer test-file ${FILE}
1313

1414
test-no-coverage:
1515
@${DOCKER_RUN} composer tests-no-coverage
@@ -22,4 +22,4 @@ show-reports:
2222

2323
clean:
2424
@sudo chown -R ${USER}:${USER} ${PWD}
25-
@rm -rf report vendor .phpunit.cache
25+
@rm -rf report vendor .phpunit.cache .lock

README.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ declare(strict_types=1);
6363
namespace Example;
6464

6565
use TinyBlocks\Collection\Collection;
66-
use TinyBlocks\Collection\Internal\Operations\Order\Order;
67-
use TinyBlocks\Collection\Internal\Operations\Transform\PreserveKeys;
66+
use TinyBlocks\Collection\Order;
67+
use TinyBlocks\Collection\PreserveKeys;
6868

6969
$collection = Collection::createFrom(elements: [1, 2, 3, 4, 5])
7070
->add(elements: [6, 7])
@@ -159,7 +159,7 @@ These methods enable sorting elements in the Collection based on the specified o
159159
By default, `Order::ASCENDING_KEY` is used.
160160
161161
```php
162-
use TinyBlocks\Collection\Internal\Operations\Order\Order;
162+
use TinyBlocks\Collection\Order;
163163
164164
$collection->sort(order: Order::DESCENDING_VALUE);
165165
```
@@ -168,7 +168,7 @@ These methods enable sorting elements in the Collection based on the specified o
168168
compared.
169169

170170
```php
171-
use TinyBlocks\Collection\Internal\Operations\Order\Order;
171+
use TinyBlocks\Collection\Order;
172172

173173
$collection->sort(order: Order::ASCENDING_VALUE, predicate: fn(Amount $amount): float => $amount->value);
174174
```
@@ -296,6 +296,18 @@ These methods allow the Collection's elements to be transformed or converted int
296296
$collection->map(transformations: fn(int $value): int => $value * 2);
297297
```
298298

299+
#### Flattening elements
300+
301+
- `flatten`: Flattens a collection by removing any nested collections and returning a single collection with all
302+
elements in a single level.
303+
304+
This method recursively flattens any iterable elements, combining them into one collection, regardless of their
305+
nesting depth.
306+
307+
```php
308+
$collection->flatten();
309+
```
310+
299311
#### Convert to array
300312

301313
- `toArray`: Converts the Collection into an array.
@@ -308,7 +320,7 @@ These methods allow the Collection's elements to be transformed or converted int
308320
By default, `PreserveKeys::PRESERVE` is used.
309321

310322
```php
311-
use TinyBlocks\Collection\Internal\Operations\Transform\PreserveKeys;
323+
use TinyBlocks\Collection\PreserveKeys;
312324

313325
$collection->toArray(preserveKeys: PreserveKeys::DISCARD);
314326
```
@@ -325,7 +337,7 @@ These methods allow the Collection's elements to be transformed or converted int
325337
By default, `PreserveKeys::PRESERVE` is used.
326338

327339
```php
328-
use TinyBlocks\Collection\Internal\Operations\Transform\PreserveKeys;
340+
use TinyBlocks\Collection\PreserveKeys;
329341

330342
$collection->toJson(preserveKeys: PreserveKeys::DISCARD);
331343
```
@@ -352,8 +364,8 @@ Lazy evaluation, enabled by [PHP's Generators](https://www.php.net/manual/en/lan
352364
This results in significant memory savings when working with large datasets or performing complex
353365
chained operations.
354366

355-
However, this also means that some operations will entirely consume the generator, and you won't be
356-
able to reaccess the elements unless you recreate the `Collection`.
367+
However, this also means that some operations will consume the generator, and you cannot access the elements unless you
368+
recreate the `Collection`.
357369

358370
<div id='license'></div>
359371

composer.json

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,38 +44,34 @@
4444
}
4545
},
4646
"require": {
47-
"php": "^8.2",
47+
"php": "^8.3",
4848
"tiny-blocks/serializer": "^3"
4949
},
5050
"require-dev": {
5151
"phpmd/phpmd": "^2.15",
5252
"phpunit/phpunit": "^11",
5353
"phpstan/phpstan": "^1",
54-
"infection/infection": "^0.29",
55-
"squizlabs/php_codesniffer": "^3.10"
54+
"infection/infection": "^0",
55+
"squizlabs/php_codesniffer": "^3"
5656
},
5757
"scripts": {
58+
"test": "phpunit -d memory_limit=2G --configuration phpunit.xml tests",
5859
"phpcs": "phpcs --standard=PSR12 --extensions=php ./src",
5960
"phpmd": "phpmd ./src text phpmd.xml --suffixes php --ignore-violations-on-exit",
6061
"phpstan": "phpstan analyse -c phpstan.neon.dist --quiet --no-progress",
61-
"test": "phpunit --log-junit=report/coverage/junit.xml --coverage-xml=report/coverage/coverage-xml --coverage-html=report/coverage/coverage-html tests",
62-
"test-mutation": "infection --only-covered --logger-html=report/coverage/mutation-report.html --coverage=report/coverage --min-msi=100 --min-covered-msi=100 --threads=4",
63-
"test-no-coverage": "phpunit --no-coverage",
64-
"test-mutation-no-coverage": "infection --only-covered --min-msi=100 --threads=4",
62+
"test-file": "phpunit --configuration phpunit.xml --no-coverage --filter",
63+
"mutation-test": "infection --only-covered --threads=max --logger-html=report/coverage/mutation-report.html --coverage=report/coverage",
64+
"test-no-coverage": "phpunit --configuration phpunit.xml --no-coverage tests",
6565
"review": [
6666
"@phpcs",
6767
"@phpmd",
6868
"@phpstan"
6969
],
7070
"tests": [
7171
"@test",
72-
"@test-mutation"
72+
"@mutation-test"
7373
],
7474
"tests-no-coverage": [
75-
"@test-no-coverage",
76-
"@test-mutation-no-coverage"
77-
],
78-
"tests-file-no-coverage": [
7975
"@test-no-coverage"
8076
]
8177
}

infection.json.dist

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
{
2-
"timeout": 10,
3-
"testFramework": "phpunit",
2+
"logs": {
3+
"text": "report/infection/logs/infection-text.log",
4+
"summary": "report/infection/logs/infection-summary.log"
5+
},
46
"tmpDir": "report/infection/",
7+
"minMsi": 100,
8+
"timeout": 30,
59
"source": {
610
"directories": [
711
"src"
812
]
913
},
10-
"logs": {
11-
"text": "report/infection/logs/infection-text.log",
12-
"summary": "report/infection/logs/infection-summary.log"
14+
"phpUnit": {
15+
"configDir": "",
16+
"customPath": "./vendor/bin/phpunit"
1317
},
1418
"mutators": {
1519
"@default": true
1620
},
17-
"phpUnit": {
18-
"configDir": "",
19-
"customPath": "./vendor/bin/phpunit"
20-
}
21-
}
21+
"minCoveredMsi": 100,
22+
"testFramework": "phpunit"
23+
}

phpunit.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
failOnRisky="true"
77
failOnWarning="true"
88
cacheDirectory=".phpunit.cache"
9+
executionOrder="random"
910
beStrictAboutOutputDuringTests="true">
1011

1112
<source>
@@ -22,14 +23,15 @@
2223

2324
<coverage>
2425
<report>
26+
<xml outputDirectory="report/coverage/coverage-xml"/>
27+
<html outputDirectory="report/coverage/coverage-html"/>
2528
<text outputFile="report/coverage.txt"/>
26-
<html outputDirectory="report/html/"/>
2729
<clover outputFile="report/coverage-clover.xml"/>
2830
</report>
2931
</coverage>
3032

3133
<logging>
32-
<junit outputFile="report/execution-result.xml"/>
34+
<junit outputFile="report/coverage/junit.xml"/>
3335
</logging>
3436

3537
</phpunit>

0 commit comments

Comments
 (0)