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 composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
"require": {
"php": "^8.3",
"tiny-blocks/collection": "1.7.0"
"tiny-blocks/collection": "1.8.0"
},
"require-dev": {
"phpmd/phpmd": "^2.15",
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Mappers/Collection/ArrayMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function map(mixed $value, KeyPreservation $keyPreservation): array

if ($valueMapper->valueIsCollectible(value: $value)) {
$collectionMapper = new CollectionMapper(valueMapper: $valueMapper);
$mappedValues = $collectionMapper->map(value: $value, keyPreservation: $keyPreservation);
return $collectionMapper->map(value: $value, keyPreservation: $keyPreservation);
}

$reflectionClass = new ReflectionClass($value);
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Mappers/Collection/CollectionMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public function map(Collectible $value, KeyPreservation $keyPreservation): array
$mappedValues[$key] = $this->valueMapper->map(value: $element, keyPreservation: $keyPreservation);
}

return $mappedValues;
return $keyPreservation->shouldPreserveKeys() ? $mappedValues : array_values($mappedValues);
}
}
151 changes: 151 additions & 0 deletions tests/Models/Collection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?php

declare(strict_types=1);

namespace TinyBlocks\Mapper\Models;

use Closure;
use TinyBlocks\Collection\Collectible;
use TinyBlocks\Collection\PreserveKeys;
use TinyBlocks\Mapper\IterableMappability;
use TinyBlocks\Mapper\IterableMapper;
use Traversable;

final readonly class Collection implements Collectible
{
//use IterableMappability;

private iterable $iterator;

private function __construct(iterable $iterator)
{
$this->iterator = $iterator;
}

public static function createFrom(iterable $elements): Collectible
{
return new Collection(iterator: $elements);
}

public static function createFromEmpty(): Collectible
{
// TODO: Implement createFromEmpty() method.
}

public function add(...$elements): Collectible
{
// TODO: Implement add() method.
}

public function contains(mixed $element): bool
{
// TODO: Implement contains() method.
}

public function count(): int
{
return iterator_count($this->iterator);
}

public function each(Closure ...$actions): Collectible
{
// TODO: Implement each() method.
}

public function equals(Collectible $other): bool
{
// TODO: Implement equals() method.
}

public function filter(?Closure ...$predicates): Collectible
{
// TODO: Implement filter() method.
}

public function findBy(Closure ...$predicates): mixed
{
// TODO: Implement findBy() method.
}

public function first(mixed $defaultValueIfNotFound = null): mixed
{
// TODO: Implement first() method.
}

public function flatten(): Collectible
{
// TODO: Implement flatten() method.
}

public function getBy(int $index, mixed $defaultValueIfNotFound = null): mixed
{
// TODO: Implement getBy() method.
}

public function getIterator(): Traversable
{
yield from $this->iterator;
}

public function groupBy(Closure $grouping): Collectible
{
// TODO: Implement groupBy() method.
}

public function isEmpty(): bool
{
// TODO: Implement isEmpty() method.
}

public function joinToString(string $separator): string
{
// TODO: Implement joinToString() method.
}

public function last(mixed $defaultValueIfNotFound = null): mixed
{
// TODO: Implement last() method.
}

public function map(Closure ...$transformations): Collectible
{
// TODO: Implement map() method.
}

public function remove(mixed $element): Collectible
{
// TODO: Implement remove() method.
}

public function removeAll(?Closure $filter = null): Collectible
{
// TODO: Implement removeAll() method.
}

public function reduce(Closure $aggregator, mixed $initial): mixed
{
// TODO: Implement reduce() method.
}

public function sort(
\TinyBlocks\Collection\Order $order = \TinyBlocks\Collection\Order::ASCENDING_KEY,
?Closure $predicate = null
): Collectible {
// TODO: Implement sort() method.
}

public function slice(int $index, int $length = -1): Collectible
{
// TODO: Implement slice() method.
}

public function toArray(PreserveKeys $preserveKeys = PreserveKeys::PRESERVE): array
{
// TODO: Implement toArray() method.
}

public function toJson(PreserveKeys $preserveKeys = PreserveKeys::PRESERVE): string
{
// TODO: Implement toJson() method.
}
}
11 changes: 0 additions & 11 deletions tests/Models/InvoiceSummaries.php

This file was deleted.

12 changes: 0 additions & 12 deletions tests/Models/InvoiceSummary.php

This file was deleted.

Loading