Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test: ## Run all tests with coverage
@${DOCKER_RUN} composer tests

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

.PHONY: test-no-coverage
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ These methods enable adding, removing, and modifying elements in the Collection.
- **With a filter**: Removes only the elements that match the provided filter.

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

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

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

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

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

<div id='retrieving'></div>
Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,19 @@
},
"autoload-dev": {
"psr-4": {
"TinyBlocks\\Collection\\": "tests/"
"Test\\TinyBlocks\\Collection\\": "tests/"
}
},
"require": {
"php": "^8.5",
"tiny-blocks/mapper": "1.2.*"
"tiny-blocks/mapper": "1.4.*"
},
"require-dev": {
"phpunit/phpunit": "^11.5",
"phpstan/phpstan": "^2.1",
"infection/infection": "^0.32",
"squizlabs/php_codesniffer": "^3.13"
"tiny-blocks/currency": "^2.3",
"squizlabs/php_codesniffer": "^4.0"
},
"scripts": {
"test": "php -d memory_limit=2G ./vendor/bin/phpunit --configuration phpunit.xml tests",
Expand Down
8 changes: 5 additions & 3 deletions src/Internal/Operations/Order/Sort.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ public static function from(Order $order, ?Closure $predicate = null): Sort

public function apply(iterable $elements): Generator
{
$temporaryElements = [];
$temporaryElements = is_array($elements) ? $elements : [];

foreach ($elements as $key => $value) {
$temporaryElements[$key] = $value;
if (!is_array($elements)) {
foreach ($elements as $key => $value) {
$temporaryElements[$key] = $value;
}
}

$predicate = is_null($this->predicate)
Expand Down
4 changes: 0 additions & 4 deletions src/Internal/Operations/Retrieve/First.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ public static function from(iterable $elements): First

public function element(mixed $defaultValueIfNotFound = null): mixed
{
if (is_array($this->elements)) {
return array_first($this->elements) ?? $defaultValueIfNotFound;
}

foreach ($this->elements as $element) {
return $element;
}
Expand Down
4 changes: 0 additions & 4 deletions src/Internal/Operations/Retrieve/Last.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ public static function from(iterable $elements): Last

public function element(mixed $defaultValueIfNotFound = null): mixed
{
if (is_array($this->elements)) {
return array_last($this->elements) ?? $defaultValueIfNotFound;
}

$lastElement = $defaultValueIfNotFound;

foreach ($this->elements as $element) {
Expand Down
12 changes: 4 additions & 8 deletions src/Internal/Operations/Transform/Each.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@ public static function from(Closure ...$actions): Each

public function execute(iterable $elements): void
{
$runActions = static function (iterable $actions) use ($elements): void {
foreach ($elements as $key => $value) {
foreach ($actions as $action) {
$action($value, $key);
}
foreach ($elements as $key => $value) {
foreach ($this->actions as $action) {
$action($value, $key);
}
};

$runActions($this->actions);
}
}
}
3 changes: 2 additions & 1 deletion tests/CollectionIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

declare(strict_types=1);

namespace TinyBlocks\Collection;
namespace Test\TinyBlocks\Collection;

use PHPUnit\Framework\TestCase;
use TinyBlocks\Collection\Collection;

final class CollectionIteratorTest extends TestCase
{
Expand Down
8 changes: 5 additions & 3 deletions tests/CollectionPerformanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

declare(strict_types=1);

namespace TinyBlocks\Collection;
namespace Test\TinyBlocks\Collection;

use Generator;
use PHPUnit\Framework\TestCase;
use TinyBlocks\Collection\Models\Amount;
use TinyBlocks\Collection\Models\Currency;
use Test\TinyBlocks\Collection\Models\Amount;
use TinyBlocks\Collection\Collection;
use TinyBlocks\Collection\Order;
use TinyBlocks\Currency\Currency;

final class CollectionPerformanceTest extends TestCase
{
Expand Down
8 changes: 5 additions & 3 deletions tests/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

declare(strict_types=1);

namespace TinyBlocks\Collection;
namespace Test\TinyBlocks\Collection;

use PHPUnit\Framework\TestCase;
use TinyBlocks\Collection\Models\Amount;
use TinyBlocks\Collection\Models\Currency;
use Test\TinyBlocks\Collection\Models\Amount;
use TinyBlocks\Collection\Collection;
use TinyBlocks\Collection\Order;
use TinyBlocks\Currency\Currency;

final class CollectionTest extends TestCase
{
Expand Down
4 changes: 3 additions & 1 deletion tests/Models/Amount.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

declare(strict_types=1);

namespace TinyBlocks\Collection\Models;
namespace Test\TinyBlocks\Collection\Models;

use TinyBlocks\Currency\Currency;

final class Amount
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Models/CryptoCurrency.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace TinyBlocks\Collection\Models;
namespace Test\TinyBlocks\Collection\Models;

use TinyBlocks\Mapper\ObjectMappability;
use TinyBlocks\Mapper\ObjectMapper;
Expand Down
12 changes: 0 additions & 12 deletions tests/Models/Currency.php

This file was deleted.

2 changes: 1 addition & 1 deletion tests/Models/Dragon.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace TinyBlocks\Collection\Models;
namespace Test\TinyBlocks\Collection\Models;

final readonly class Dragon
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Models/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace TinyBlocks\Collection\Models;
namespace Test\TinyBlocks\Collection\Models;

final class Invoice
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Models/InvoiceSummaries.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace TinyBlocks\Collection\Models;
namespace Test\TinyBlocks\Collection\Models;

use TinyBlocks\Collection\Collection;

Expand Down
2 changes: 1 addition & 1 deletion tests/Models/InvoiceSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace TinyBlocks\Collection\Models;
namespace Test\TinyBlocks\Collection\Models;

final class InvoiceSummary
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Models/Invoices.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace TinyBlocks\Collection\Models;
namespace Test\TinyBlocks\Collection\Models;

use TinyBlocks\Collection\Collection;

Expand Down
2 changes: 1 addition & 1 deletion tests/Models/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace TinyBlocks\Collection\Models;
namespace Test\TinyBlocks\Collection\Models;

final readonly class Order
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace TinyBlocks\Collection\Models;
namespace Test\TinyBlocks\Collection\Models;

use TinyBlocks\Mapper\ObjectMappability;
use TinyBlocks\Mapper\ObjectMapper;
Expand Down
2 changes: 1 addition & 1 deletion tests/Models/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace TinyBlocks\Collection\Models;
namespace Test\TinyBlocks\Collection\Models;

use ArrayIterator;
use IteratorAggregate;
Expand Down
2 changes: 1 addition & 1 deletion tests/Models/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace TinyBlocks\Collection\Models;
namespace Test\TinyBlocks\Collection\Models;

enum Status: int
{
Expand Down
6 changes: 3 additions & 3 deletions tests/Operations/Aggregate/CollectionReduceOperationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

namespace TinyBlocks\Collection\Operations\Aggregate;
namespace Test\TinyBlocks\Collection\Operations\Aggregate;

use PHPUnit\Framework\TestCase;
use TinyBlocks\Collection\Models\InvoiceSummaries;
use TinyBlocks\Collection\Models\InvoiceSummary;
use Test\TinyBlocks\Collection\Models\InvoiceSummaries;
use Test\TinyBlocks\Collection\Models\InvoiceSummary;

final class CollectionReduceOperationTest extends TestCase
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Operations/Compare/CollectionContainsOperationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

declare(strict_types=1);

namespace TinyBlocks\Collection\Operations\Compare;
namespace Test\TinyBlocks\Collection\Operations\Compare;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use stdClass;
use Test\TinyBlocks\Collection\Models\CryptoCurrency;
use TinyBlocks\Collection\Collection;
use TinyBlocks\Collection\Models\CryptoCurrency;

final class CollectionContainsOperationTest extends TestCase
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Operations/Compare/CollectionEqualsOperationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

declare(strict_types=1);

namespace TinyBlocks\Collection\Operations\Compare;
namespace Test\TinyBlocks\Collection\Operations\Compare;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use stdClass;
use Test\TinyBlocks\Collection\Models\CryptoCurrency;
use TinyBlocks\Collection\Collection;
use TinyBlocks\Collection\Models\CryptoCurrency;

final class CollectionEqualsOperationTest extends TestCase
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Operations/Filter/CollectionFilterOperationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

declare(strict_types=1);

namespace TinyBlocks\Collection\Operations\Filter;
namespace Test\TinyBlocks\Collection\Operations\Filter;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Test\TinyBlocks\Collection\Models\CryptoCurrency;
use TinyBlocks\Collection\Collection;
use TinyBlocks\Collection\Models\CryptoCurrency;
use TinyBlocks\Mapper\KeyPreservation;

final class CollectionFilterOperationTest extends TestCase
Expand Down
6 changes: 3 additions & 3 deletions tests/Operations/Order/CollectionSortOperationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

declare(strict_types=1);

namespace TinyBlocks\Collection\Operations\Order;
namespace Test\TinyBlocks\Collection\Operations\Order;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Test\TinyBlocks\Collection\Models\Amount;
use TinyBlocks\Collection\Collection;
use TinyBlocks\Collection\Models\Amount;
use TinyBlocks\Collection\Models\Currency;
use TinyBlocks\Collection\Order;
use TinyBlocks\Currency\Currency;

final class CollectionSortOperationTest extends TestCase
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Operations/Retrieve/CollectionFindOperationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

namespace TinyBlocks\Collection\Operations\Retrieve;
namespace Test\TinyBlocks\Collection\Operations\Retrieve;

use PHPUnit\Framework\TestCase;
use Test\TinyBlocks\Collection\Models\CryptoCurrency;
use TinyBlocks\Collection\Collection;
use TinyBlocks\Collection\Models\CryptoCurrency;

final class CollectionFindOperationTest extends TestCase
{
Expand Down
Loading