Skip to content

Commit 0c9b26d

Browse files
authored
Release/1.0.3 (#9)
* fix: Fixes Collection to array mapping.
1 parent 8a75cf9 commit 0c9b26d

File tree

6 files changed

+154
-26
lines changed

6 files changed

+154
-26
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
},
4444
"require": {
4545
"php": "^8.3",
46-
"tiny-blocks/collection": "1.7.0"
46+
"tiny-blocks/collection": "1.8.0"
4747
},
4848
"require-dev": {
4949
"phpmd/phpmd": "^2.15",

src/Internal/Mappers/Collection/ArrayMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function map(mixed $value, KeyPreservation $keyPreservation): array
1616

1717
if ($valueMapper->valueIsCollectible(value: $value)) {
1818
$collectionMapper = new CollectionMapper(valueMapper: $valueMapper);
19-
$mappedValues = $collectionMapper->map(value: $value, keyPreservation: $keyPreservation);
19+
return $collectionMapper->map(value: $value, keyPreservation: $keyPreservation);
2020
}
2121

2222
$reflectionClass = new ReflectionClass($value);

src/Internal/Mappers/Collection/CollectionMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ public function map(Collectible $value, KeyPreservation $keyPreservation): array
2121
$mappedValues[$key] = $this->valueMapper->map(value: $element, keyPreservation: $keyPreservation);
2222
}
2323

24-
return $mappedValues;
24+
return $keyPreservation->shouldPreserveKeys() ? $mappedValues : array_values($mappedValues);
2525
}
2626
}

tests/Models/Collection.php

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TinyBlocks\Mapper\Models;
6+
7+
use Closure;
8+
use TinyBlocks\Collection\Collectible;
9+
use TinyBlocks\Collection\PreserveKeys;
10+
use TinyBlocks\Mapper\IterableMappability;
11+
use TinyBlocks\Mapper\IterableMapper;
12+
use Traversable;
13+
14+
final readonly class Collection implements Collectible
15+
{
16+
//use IterableMappability;
17+
18+
private iterable $iterator;
19+
20+
private function __construct(iterable $iterator)
21+
{
22+
$this->iterator = $iterator;
23+
}
24+
25+
public static function createFrom(iterable $elements): Collectible
26+
{
27+
return new Collection(iterator: $elements);
28+
}
29+
30+
public static function createFromEmpty(): Collectible
31+
{
32+
// TODO: Implement createFromEmpty() method.
33+
}
34+
35+
public function add(...$elements): Collectible
36+
{
37+
// TODO: Implement add() method.
38+
}
39+
40+
public function contains(mixed $element): bool
41+
{
42+
// TODO: Implement contains() method.
43+
}
44+
45+
public function count(): int
46+
{
47+
return iterator_count($this->iterator);
48+
}
49+
50+
public function each(Closure ...$actions): Collectible
51+
{
52+
// TODO: Implement each() method.
53+
}
54+
55+
public function equals(Collectible $other): bool
56+
{
57+
// TODO: Implement equals() method.
58+
}
59+
60+
public function filter(?Closure ...$predicates): Collectible
61+
{
62+
// TODO: Implement filter() method.
63+
}
64+
65+
public function findBy(Closure ...$predicates): mixed
66+
{
67+
// TODO: Implement findBy() method.
68+
}
69+
70+
public function first(mixed $defaultValueIfNotFound = null): mixed
71+
{
72+
// TODO: Implement first() method.
73+
}
74+
75+
public function flatten(): Collectible
76+
{
77+
// TODO: Implement flatten() method.
78+
}
79+
80+
public function getBy(int $index, mixed $defaultValueIfNotFound = null): mixed
81+
{
82+
// TODO: Implement getBy() method.
83+
}
84+
85+
public function getIterator(): Traversable
86+
{
87+
yield from $this->iterator;
88+
}
89+
90+
public function groupBy(Closure $grouping): Collectible
91+
{
92+
// TODO: Implement groupBy() method.
93+
}
94+
95+
public function isEmpty(): bool
96+
{
97+
// TODO: Implement isEmpty() method.
98+
}
99+
100+
public function joinToString(string $separator): string
101+
{
102+
// TODO: Implement joinToString() method.
103+
}
104+
105+
public function last(mixed $defaultValueIfNotFound = null): mixed
106+
{
107+
// TODO: Implement last() method.
108+
}
109+
110+
public function map(Closure ...$transformations): Collectible
111+
{
112+
// TODO: Implement map() method.
113+
}
114+
115+
public function remove(mixed $element): Collectible
116+
{
117+
// TODO: Implement remove() method.
118+
}
119+
120+
public function removeAll(?Closure $filter = null): Collectible
121+
{
122+
// TODO: Implement removeAll() method.
123+
}
124+
125+
public function reduce(Closure $aggregator, mixed $initial): mixed
126+
{
127+
// TODO: Implement reduce() method.
128+
}
129+
130+
public function sort(
131+
\TinyBlocks\Collection\Order $order = \TinyBlocks\Collection\Order::ASCENDING_KEY,
132+
?Closure $predicate = null
133+
): Collectible {
134+
// TODO: Implement sort() method.
135+
}
136+
137+
public function slice(int $index, int $length = -1): Collectible
138+
{
139+
// TODO: Implement slice() method.
140+
}
141+
142+
public function toArray(PreserveKeys $preserveKeys = PreserveKeys::PRESERVE): array
143+
{
144+
// TODO: Implement toArray() method.
145+
}
146+
147+
public function toJson(PreserveKeys $preserveKeys = PreserveKeys::PRESERVE): string
148+
{
149+
// TODO: Implement toJson() method.
150+
}
151+
}

tests/Models/InvoiceSummaries.php

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/Models/InvoiceSummary.php

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)