Skip to content

Commit 8edeea4

Browse files
authored
Release/1.13.0 (#34)
1 parent cb1bbc0 commit 8edeea4

42 files changed

Lines changed: 156 additions & 114 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ test: ## Run all tests with coverage
2323
@${DOCKER_RUN} composer tests
2424

2525
.PHONY: test-file
26-
test-file: ## Run tests for a specific file (usage: make test-file FILE=path/to/file)
26+
test-file: ## Run tests for a specific file (usage: make test-file FILE=ClassNameTest)
2727
@${DOCKER_RUN} composer test-file ${FILE}
2828

2929
.PHONY: test-no-coverage

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ These methods enable adding, removing, and modifying elements in the Collection.
107107
- **With a filter**: Removes only the elements that match the provided filter.
108108

109109
```php
110-
$collection->removeAll(filter: fn(Amount $amount): bool => $amount->value > 10.0);
110+
$collection->removeAll(filter: static fn(Amount $amount): bool => $amount->value > 10.0);
111111
```
112112

113113
- **Without a filter**: Removes all elements from the Collection.
@@ -130,7 +130,7 @@ These methods enable filtering elements in the Collection based on specific cond
130130
- **With predicates**: Filter elements are based on the provided predicates.
131131

132132
```php
133-
$collection->filter(predicates: fn(Amount $amount): bool => $amount->value > 100);
133+
$collection->filter(predicates: static fn(Amount $amount): bool => $amount->value > 100);
134134
```
135135

136136
- **Without predicates**: Removes all empty or false values (e.g., `null`, `false`, empty arrays).
@@ -170,7 +170,7 @@ These methods enable sorting elements in the Collection based on the specified o
170170
```php
171171
use TinyBlocks\Collection\Order;
172172

173-
$collection->sort(order: Order::ASCENDING_VALUE, predicate: fn(Amount $amount): float => $amount->value);
173+
$collection->sort(order: Order::ASCENDING_VALUE, predicate: static fn(Amount $amount): float => $amount->value);
174174
```
175175

176176
<div id='retrieving'></div>

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,19 @@
4040
},
4141
"autoload-dev": {
4242
"psr-4": {
43-
"TinyBlocks\\Collection\\": "tests/"
43+
"Test\\TinyBlocks\\Collection\\": "tests/"
4444
}
4545
},
4646
"require": {
4747
"php": "^8.5",
48-
"tiny-blocks/mapper": "1.2.*"
48+
"tiny-blocks/mapper": "1.4.*"
4949
},
5050
"require-dev": {
5151
"phpunit/phpunit": "^11.5",
5252
"phpstan/phpstan": "^2.1",
5353
"infection/infection": "^0.32",
54-
"squizlabs/php_codesniffer": "^3.13"
54+
"tiny-blocks/currency": "^2.3",
55+
"squizlabs/php_codesniffer": "^4.0"
5556
},
5657
"scripts": {
5758
"test": "php -d memory_limit=2G ./vendor/bin/phpunit --configuration phpunit.xml tests",

src/Internal/Operations/Order/Sort.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ public static function from(Order $order, ?Closure $predicate = null): Sort
2222

2323
public function apply(iterable $elements): Generator
2424
{
25-
$temporaryElements = [];
25+
$temporaryElements = is_array($elements) ? $elements : [];
2626

27-
foreach ($elements as $key => $value) {
28-
$temporaryElements[$key] = $value;
27+
if (!is_array($elements)) {
28+
foreach ($elements as $key => $value) {
29+
$temporaryElements[$key] = $value;
30+
}
2931
}
3032

3133
$predicate = is_null($this->predicate)

src/Internal/Operations/Retrieve/First.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ public static function from(iterable $elements): First
1919

2020
public function element(mixed $defaultValueIfNotFound = null): mixed
2121
{
22-
if (is_array($this->elements)) {
23-
return array_first($this->elements) ?? $defaultValueIfNotFound;
24-
}
25-
2622
foreach ($this->elements as $element) {
2723
return $element;
2824
}

src/Internal/Operations/Retrieve/Last.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ public static function from(iterable $elements): Last
1919

2020
public function element(mixed $defaultValueIfNotFound = null): mixed
2121
{
22-
if (is_array($this->elements)) {
23-
return array_last($this->elements) ?? $defaultValueIfNotFound;
24-
}
25-
2622
$lastElement = $defaultValueIfNotFound;
2723

2824
foreach ($this->elements as $element) {

src/Internal/Operations/Transform/Each.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,10 @@ public static function from(Closure ...$actions): Each
2323

2424
public function execute(iterable $elements): void
2525
{
26-
$runActions = static function (iterable $actions) use ($elements): void {
27-
foreach ($elements as $key => $value) {
28-
foreach ($actions as $action) {
29-
$action($value, $key);
30-
}
26+
foreach ($elements as $key => $value) {
27+
foreach ($this->actions as $action) {
28+
$action($value, $key);
3129
}
32-
};
33-
34-
$runActions($this->actions);
30+
}
3531
}
3632
}

tests/CollectionIteratorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
declare(strict_types=1);
44

5-
namespace TinyBlocks\Collection;
5+
namespace Test\TinyBlocks\Collection;
66

77
use PHPUnit\Framework\TestCase;
8+
use TinyBlocks\Collection\Collection;
89

910
final class CollectionIteratorTest extends TestCase
1011
{

tests/CollectionPerformanceTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
declare(strict_types=1);
44

5-
namespace TinyBlocks\Collection;
5+
namespace Test\TinyBlocks\Collection;
66

77
use Generator;
88
use PHPUnit\Framework\TestCase;
9-
use TinyBlocks\Collection\Models\Amount;
10-
use TinyBlocks\Collection\Models\Currency;
9+
use Test\TinyBlocks\Collection\Models\Amount;
10+
use TinyBlocks\Collection\Collection;
11+
use TinyBlocks\Collection\Order;
12+
use TinyBlocks\Currency\Currency;
1113

1214
final class CollectionPerformanceTest extends TestCase
1315
{

tests/CollectionTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
declare(strict_types=1);
44

5-
namespace TinyBlocks\Collection;
5+
namespace Test\TinyBlocks\Collection;
66

77
use PHPUnit\Framework\TestCase;
8-
use TinyBlocks\Collection\Models\Amount;
9-
use TinyBlocks\Collection\Models\Currency;
8+
use Test\TinyBlocks\Collection\Models\Amount;
9+
use TinyBlocks\Collection\Collection;
10+
use TinyBlocks\Collection\Order;
11+
use TinyBlocks\Currency\Currency;
1012

1113
final class CollectionTest extends TestCase
1214
{

0 commit comments

Comments
 (0)