Skip to content

Commit

Permalink
Merge pull request #231 from alikallali/feature/add-support-php-8.3
Browse files Browse the repository at this point in the history
Add PHP 8.3 support
  • Loading branch information
boesing committed Jan 25, 2024
2 parents b605b67 + ccea1c6 commit 3496b9f
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 95 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Hashmap and Collection",
"license": "MIT",
"require": {
"php": "~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0",
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
"webmozart/assert": "^1.9"
},
"require-dev": {
Expand Down
24 changes: 19 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions src/AbstractForAllPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,15 @@ abstract class AbstractForAllPromise implements ForAllPromiseInterface

private bool $executed = false;

/** @var iterable<TKey,TValue> */
private iterable $iterable;

/** @var callable(TValue,TKey):void */
private $callback;

/**
* @param iterable<TKey,TValue> $iterable
* @param callable(TValue,TKey):void $callback
*/
final public function __construct(iterable $iterable, callable $callback)
final public function __construct(private iterable $iterable, callable $callback)
{
$this->iterable = $iterable;
$this->callback = $callback;
}

Expand Down
6 changes: 1 addition & 5 deletions src/Array_.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,11 @@
*/
abstract class Array_ implements ArrayInterface
{
/** @psalm-var array<TKey,TValue> */
protected array $data;

/**
* @psalm-param array<TKey,TValue> $data
*/
protected function __construct(array $data)
protected function __construct(protected array $data)
{
$this->data = $data;
}

/**
Expand Down
26 changes: 13 additions & 13 deletions src/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function merge(MapInterface ...$stack): MapInterface
return $instance;
}

public function sort(?callable $callback = null): MapInterface
public function sort(callable|null $callback = null): MapInterface
{
$instance = clone $this;
$data = $instance->data;
Expand All @@ -79,7 +79,7 @@ public function sort(?callable $callback = null): MapInterface
return $instance;
}

public function diffKeys(MapInterface $other, ?callable $keyComparator = null): MapInterface
public function diffKeys(MapInterface $other, callable|null $keyComparator = null): MapInterface
{
$instance = clone $this;
$otherData = $other->toNativeArray();
Expand Down Expand Up @@ -117,7 +117,7 @@ private function keyComparator(): callable
};
}

public function toOrderedList(?callable $sorter = null): OrderedListInterface
public function toOrderedList(callable|null $sorter = null): OrderedListInterface
{
if ($sorter === null) {
return new GenericOrderedList(array_values($this->data));
Expand Down Expand Up @@ -184,7 +184,7 @@ public function get(string $key)
return $this->data[$key];
}

public function intersect(MapInterface $other, ?callable $valueComparator = null): MapInterface
public function intersect(MapInterface $other, callable|null $valueComparator = null): MapInterface
{
$instance = clone $this;
$instance->data = $instance->intersection($other, $valueComparator, null);
Expand All @@ -199,7 +199,7 @@ public function intersect(MapInterface $other, ?callable $valueComparator = null
* @psalm-return array<TKey,TValue>
* @phpcsSuppress SlevomatCodingStandard.Classes.UnusedPrivateElements.UnusedMethod
*/
private function intersection(MapInterface $other, ?callable $valueComparator, ?callable $keyComparator): array
private function intersection(MapInterface $other, callable|null $valueComparator, callable|null $keyComparator): array
{
if ($valueComparator && $keyComparator) {
/**
Expand Down Expand Up @@ -242,15 +242,15 @@ private function intersection(MapInterface $other, ?callable $valueComparator, ?
return $intersection;
}

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

return $instance;
}

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

public function intersectUserAssoc(
MapInterface $other,
?callable $valueComparator = null,
?callable $keyComparator = null
callable|null $valueComparator = null,
callable|null $keyComparator = null,
): MapInterface {
$instance = clone $this;
$instance->data = $instance->intersection($other, $valueComparator, $keyComparator);

return $instance;
}

public function diff(MapInterface $other, ?callable $valueComparator = null): MapInterface
public function diff(MapInterface $other, callable|null $valueComparator = null): MapInterface
{
/**
* @psalm-var array<TKey,TValue> $diff1
Expand Down Expand Up @@ -396,7 +396,7 @@ public function group(callable $callback): MapInterface
$groupIdentifier = $callback($value);
try {
$group = $groups->get($groupIdentifier);
} catch (OutOfBoundsException $exception) {
} catch (OutOfBoundsException) {
$group = clone $this;
$group->data = [];
}
Expand All @@ -415,7 +415,7 @@ public function slice(int $length): MapInterface
return $instance;
}

public function jsonSerialize(): ?array
public function jsonSerialize(): array|null
{
if ($this->data === []) {
return null;
Expand All @@ -429,7 +429,7 @@ public function forAll(callable $callback): ForAllPromiseInterface
return new MapForAllPromise($this->getIterator(), $callback);
}

public function sortByKey(?callable $sorter = null): MapInterface
public function sortByKey(callable|null $sorter = null): MapInterface
{
$sorter = $sorter ?? $this->keyComparator();
$data = $this->data;
Expand Down
22 changes: 11 additions & 11 deletions src/MapInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function filter(callable $callback): MapInterface;
* @psalm-param (callable(TValue,TValue):int)|null $callback
* @psalm-return MapInterface<TKey,TValue>
*/
public function sort(?callable $callback = null): MapInterface;
public function sort(callable|null $callback = null): MapInterface;

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

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

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

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

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

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

/**
* Creates an associative intersection of this map and the provided map using the provided value comparator.
Expand All @@ -192,8 +192,8 @@ public function intersectUsingKeys(MapInterface $other, ?callable $keyComparator
*/
public function intersectUserAssoc(
MapInterface $other,
?callable $valueComparator = null,
?callable $keyComparator = null
callable|null $valueComparator = null,
callable|null $keyComparator = null,
): MapInterface;

/**
Expand Down Expand Up @@ -247,7 +247,7 @@ public function forAll(callable $callback): ForAllPromiseInterface;
*
* @psalm-return MapInterface<TKey,TValue>
*/
public function sortByKey(?callable $sorter = null): MapInterface;
public function sortByKey(callable|null $sorter = null): MapInterface;

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

/**
* Returns a native array equivalent of the {@see OrderedListInterface} or the {@see MapInterface}.
Expand Down
6 changes: 1 addition & 5 deletions src/MappedErrorCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@

final class MappedErrorCollection extends RuntimeException
{
/** @var MapInterface<string,Throwable> */
private MapInterface $errors;

/**
* @param MapInterface<string,Throwable> $errors
*/
private function __construct(MapInterface $errors)
private function __construct(private MapInterface $errors)
{
Assert::false($errors->isEmpty(), 'Provided errors must not be empty!');
$this->errors = $errors;

parent::__construct('There were runtime errors while executing multiple tasks.');
}
Expand Down
6 changes: 1 addition & 5 deletions src/OrderedErrorCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@

final class OrderedErrorCollection extends RuntimeException
{
/** @var OrderedListInterface<Throwable|null> */
private OrderedListInterface $errors;

/**
* @param OrderedListInterface<Throwable|null> $errors
*/
private function __construct(OrderedListInterface $errors)
private function __construct(private OrderedListInterface $errors)
{
Assert::false($errors->isEmpty(), 'Provided errors must not be empty!');
$this->errors = $errors;

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

0 comments on commit 3496b9f

Please sign in to comment.