Skip to content

Commit 3496b9f

Browse files
authored
Merge pull request #231 from alikallali/feature/add-support-php-8.3
Add PHP 8.3 support
2 parents b605b67 + ccea1c6 commit 3496b9f

14 files changed

+82
-95
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Hashmap and Collection",
55
"license": "MIT",
66
"require": {
7-
"php": "~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0",
7+
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
88
"webmozart/assert": "^1.9"
99
},
1010
"require-dev": {

composer.lock

+19-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/AbstractForAllPromise.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,15 @@ abstract class AbstractForAllPromise implements ForAllPromiseInterface
2525

2626
private bool $executed = false;
2727

28-
/** @var iterable<TKey,TValue> */
29-
private iterable $iterable;
30-
3128
/** @var callable(TValue,TKey):void */
3229
private $callback;
3330

3431
/**
3532
* @param iterable<TKey,TValue> $iterable
3633
* @param callable(TValue,TKey):void $callback
3734
*/
38-
final public function __construct(iterable $iterable, callable $callback)
35+
final public function __construct(private iterable $iterable, callable $callback)
3936
{
40-
$this->iterable = $iterable;
4137
$this->callback = $callback;
4238
}
4339

src/Array_.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,11 @@
2727
*/
2828
abstract class Array_ implements ArrayInterface
2929
{
30-
/** @psalm-var array<TKey,TValue> */
31-
protected array $data;
32-
3330
/**
3431
* @psalm-param array<TKey,TValue> $data
3532
*/
36-
protected function __construct(array $data)
33+
protected function __construct(protected array $data)
3734
{
38-
$this->data = $data;
3935
}
4036

4137
/**

src/Map.php

+13-13
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function merge(MapInterface ...$stack): MapInterface
5858
return $instance;
5959
}
6060

61-
public function sort(?callable $callback = null): MapInterface
61+
public function sort(callable|null $callback = null): MapInterface
6262
{
6363
$instance = clone $this;
6464
$data = $instance->data;
@@ -79,7 +79,7 @@ public function sort(?callable $callback = null): MapInterface
7979
return $instance;
8080
}
8181

82-
public function diffKeys(MapInterface $other, ?callable $keyComparator = null): MapInterface
82+
public function diffKeys(MapInterface $other, callable|null $keyComparator = null): MapInterface
8383
{
8484
$instance = clone $this;
8585
$otherData = $other->toNativeArray();
@@ -117,7 +117,7 @@ private function keyComparator(): callable
117117
};
118118
}
119119

120-
public function toOrderedList(?callable $sorter = null): OrderedListInterface
120+
public function toOrderedList(callable|null $sorter = null): OrderedListInterface
121121
{
122122
if ($sorter === null) {
123123
return new GenericOrderedList(array_values($this->data));
@@ -184,7 +184,7 @@ public function get(string $key)
184184
return $this->data[$key];
185185
}
186186

187-
public function intersect(MapInterface $other, ?callable $valueComparator = null): MapInterface
187+
public function intersect(MapInterface $other, callable|null $valueComparator = null): MapInterface
188188
{
189189
$instance = clone $this;
190190
$instance->data = $instance->intersection($other, $valueComparator, null);
@@ -199,7 +199,7 @@ public function intersect(MapInterface $other, ?callable $valueComparator = null
199199
* @psalm-return array<TKey,TValue>
200200
* @phpcsSuppress SlevomatCodingStandard.Classes.UnusedPrivateElements.UnusedMethod
201201
*/
202-
private function intersection(MapInterface $other, ?callable $valueComparator, ?callable $keyComparator): array
202+
private function intersection(MapInterface $other, callable|null $valueComparator, callable|null $keyComparator): array
203203
{
204204
if ($valueComparator && $keyComparator) {
205205
/**
@@ -242,15 +242,15 @@ private function intersection(MapInterface $other, ?callable $valueComparator, ?
242242
return $intersection;
243243
}
244244

245-
public function intersectAssoc(MapInterface $other, ?callable $valueComparator = null): MapInterface
245+
public function intersectAssoc(MapInterface $other, callable|null $valueComparator = null): MapInterface
246246
{
247247
$instance = clone $this;
248248
$instance->data = $instance->intersection($other, $valueComparator, null);
249249

250250
return $instance;
251251
}
252252

253-
public function intersectUsingKeys(MapInterface $other, ?callable $keyComparator = null): MapInterface
253+
public function intersectUsingKeys(MapInterface $other, callable|null $keyComparator = null): MapInterface
254254
{
255255
$instance = clone $this;
256256
$instance->data = $instance->intersection($other, null, $keyComparator);
@@ -260,16 +260,16 @@ public function intersectUsingKeys(MapInterface $other, ?callable $keyComparator
260260

261261
public function intersectUserAssoc(
262262
MapInterface $other,
263-
?callable $valueComparator = null,
264-
?callable $keyComparator = null
263+
callable|null $valueComparator = null,
264+
callable|null $keyComparator = null,
265265
): MapInterface {
266266
$instance = clone $this;
267267
$instance->data = $instance->intersection($other, $valueComparator, $keyComparator);
268268

269269
return $instance;
270270
}
271271

272-
public function diff(MapInterface $other, ?callable $valueComparator = null): MapInterface
272+
public function diff(MapInterface $other, callable|null $valueComparator = null): MapInterface
273273
{
274274
/**
275275
* @psalm-var array<TKey,TValue> $diff1
@@ -396,7 +396,7 @@ public function group(callable $callback): MapInterface
396396
$groupIdentifier = $callback($value);
397397
try {
398398
$group = $groups->get($groupIdentifier);
399-
} catch (OutOfBoundsException $exception) {
399+
} catch (OutOfBoundsException) {
400400
$group = clone $this;
401401
$group->data = [];
402402
}
@@ -415,7 +415,7 @@ public function slice(int $length): MapInterface
415415
return $instance;
416416
}
417417

418-
public function jsonSerialize(): ?array
418+
public function jsonSerialize(): array|null
419419
{
420420
if ($this->data === []) {
421421
return null;
@@ -429,7 +429,7 @@ public function forAll(callable $callback): ForAllPromiseInterface
429429
return new MapForAllPromise($this->getIterator(), $callback);
430430
}
431431

432-
public function sortByKey(?callable $sorter = null): MapInterface
432+
public function sortByKey(callable|null $sorter = null): MapInterface
433433
{
434434
$sorter = $sorter ?? $this->keyComparator();
435435
$data = $this->data;

src/MapInterface.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function filter(callable $callback): MapInterface;
3232
* @psalm-param (callable(TValue,TValue):int)|null $callback
3333
* @psalm-return MapInterface<TKey,TValue>
3434
*/
35-
public function sort(?callable $callback = null): MapInterface;
35+
public function sort(callable|null $callback = null): MapInterface;
3636

3737
/**
3838
* Merges all maps together. Duplications are being overridden in the order they are being passed to this method.
@@ -54,7 +54,7 @@ public function merge(MapInterface ...$stack): MapInterface;
5454
* @psalm-param (callable(TKey,TKey):int)|null $keyComparator
5555
* @psalm-return MapInterface<TKey,TValue>
5656
*/
57-
public function diffKeys(MapInterface $other, ?callable $keyComparator = null): MapInterface;
57+
public function diffKeys(MapInterface $other, callable|null $keyComparator = null): MapInterface;
5858

5959
/**
6060
* Converts the items of this map to a new map of items with the return value of the provided callback.
@@ -77,7 +77,7 @@ public function map(callable $callback): MapInterface;
7777
* @psalm-param (callable(TValue,TValue):int)|null $valueComparator
7878
* @psalm-return MapInterface<TKey,TValue>
7979
*/
80-
public function intersect(MapInterface $other, ?callable $valueComparator = null): MapInterface;
80+
public function intersect(MapInterface $other, callable|null $valueComparator = null): MapInterface;
8181

8282
/**
8383
* Creates a diff of this map and the provided map while using the provided value comparator.
@@ -90,7 +90,7 @@ public function intersect(MapInterface $other, ?callable $valueComparator = null
9090
* @psalm-param (callable(TValue,TValue):int)|null $valueComparator
9191
* @psalm-return MapInterface<TKey,TValue>
9292
*/
93-
public function diff(MapInterface $other, ?callable $valueComparator = null): MapInterface;
93+
public function diff(MapInterface $other, callable|null $valueComparator = null): MapInterface;
9494

9595
/**
9696
* Creates an ordered list of the values contained in this map.
@@ -100,7 +100,7 @@ public function diff(MapInterface $other, ?callable $valueComparator = null): Ma
100100
* @psalm-param (callable(TValue,TValue):int)|null $sorter
101101
* @psalm-return OrderedListInterface<TValue>
102102
*/
103-
public function toOrderedList(?callable $sorter = null): OrderedListInterface;
103+
public function toOrderedList(callable|null $sorter = null): OrderedListInterface;
104104

105105
/**
106106
* Removes a specific element from the list. In case the element was stored multiple times, all occurrences are being
@@ -165,7 +165,7 @@ public function get(string $key);
165165
* @psalm-return MapInterface<TKey,TValue>
166166
* @psalm-param (callable(TValue,TValue):int)|null $valueComparator
167167
*/
168-
public function intersectAssoc(MapInterface $other, ?callable $valueComparator = null): MapInterface;
168+
public function intersectAssoc(MapInterface $other, callable|null $valueComparator = null): MapInterface;
169169

170170
/**
171171
* Creates an associative intersection of this map and the provided map using the provided key comparator.
@@ -176,7 +176,7 @@ public function intersectAssoc(MapInterface $other, ?callable $valueComparator =
176176
* @psalm-return MapInterface<TKey,TValue>
177177
* @psalm-param (callable(TKey,TKey):int)|null $keyComparator
178178
*/
179-
public function intersectUsingKeys(MapInterface $other, ?callable $keyComparator = null): MapInterface;
179+
public function intersectUsingKeys(MapInterface $other, callable|null $keyComparator = null): MapInterface;
180180

181181
/**
182182
* Creates an associative intersection of this map and the provided map using the provided value comparator.
@@ -192,8 +192,8 @@ public function intersectUsingKeys(MapInterface $other, ?callable $keyComparator
192192
*/
193193
public function intersectUserAssoc(
194194
MapInterface $other,
195-
?callable $valueComparator = null,
196-
?callable $keyComparator = null
195+
callable|null $valueComparator = null,
196+
callable|null $keyComparator = null,
197197
): MapInterface;
198198

199199
/**
@@ -247,7 +247,7 @@ public function forAll(callable $callback): ForAllPromiseInterface;
247247
*
248248
* @psalm-return MapInterface<TKey,TValue>
249249
*/
250-
public function sortByKey(?callable $sorter = null): MapInterface;
250+
public function sortByKey(callable|null $sorter = null): MapInterface;
251251

252252
/**
253253
* Joins all the items together.
@@ -274,7 +274,7 @@ public function keyExchange(callable $keyGenerator): MapInterface;
274274
*
275275
* @psalm-return non-empty-array<TKey,TValue>|null
276276
*/
277-
public function jsonSerialize(): ?array;
277+
public function jsonSerialize(): array|null;
278278

279279
/**
280280
* Returns a native array equivalent of the {@see OrderedListInterface} or the {@see MapInterface}.

src/MappedErrorCollection.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,12 @@
1010

1111
final class MappedErrorCollection extends RuntimeException
1212
{
13-
/** @var MapInterface<string,Throwable> */
14-
private MapInterface $errors;
15-
1613
/**
1714
* @param MapInterface<string,Throwable> $errors
1815
*/
19-
private function __construct(MapInterface $errors)
16+
private function __construct(private MapInterface $errors)
2017
{
2118
Assert::false($errors->isEmpty(), 'Provided errors must not be empty!');
22-
$this->errors = $errors;
2319

2420
parent::__construct('There were runtime errors while executing multiple tasks.');
2521
}

src/OrderedErrorCollection.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,12 @@
1010

1111
final class OrderedErrorCollection extends RuntimeException
1212
{
13-
/** @var OrderedListInterface<Throwable|null> */
14-
private OrderedListInterface $errors;
15-
1613
/**
1714
* @param OrderedListInterface<Throwable|null> $errors
1815
*/
19-
private function __construct(OrderedListInterface $errors)
16+
private function __construct(private OrderedListInterface $errors)
2017
{
2118
Assert::false($errors->isEmpty(), 'Provided errors must not be empty!');
22-
$this->errors = $errors;
2319

2420
parent::__construct('There were runtime errors while executing multiple tasks.');
2521
}

0 commit comments

Comments
 (0)