Skip to content

Commit

Permalink
chore: apply mago fmt
Browse files Browse the repository at this point in the history
Signed-off-by: azjezz <[email protected]>
  • Loading branch information
azjezz committed Dec 8, 2024
1 parent 0712fc0 commit 84a0994
Show file tree
Hide file tree
Showing 671 changed files with 5,855 additions and 5,332 deletions.
8 changes: 4 additions & 4 deletions src/Psl/Async/Awaitable.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function then(Closure $success, Closure $failure): Awaitable
* @param null|Throwable $error
* @param null|T $value
*/
static function (?Throwable $error, mixed $value) use ($state, $success, $failure): void {
static function (null|Throwable $error, mixed $value) use ($state, $success, $failure): void {
if ($error) {
try {
$state->complete($failure($error));
Expand Down Expand Up @@ -181,7 +181,7 @@ static function (?Throwable $error, mixed $value) use ($state, $success, $failur
*/
public function map(Closure $success): Awaitable
{
return $this->then($success, static fn (Throwable $throwable) => throw $throwable);
return $this->then($success, static fn(Throwable $throwable) => throw $throwable);
}

/**
Expand Down Expand Up @@ -220,7 +220,7 @@ public function always(Closure $always): Awaitable
/** @var State<T> $state */
$state = new State();

$this->state->subscribe(static function (?Throwable $error, mixed $value) use ($state, $always): void {
$this->state->subscribe(static function (null|Throwable $error, mixed $value) use ($state, $always): void {
try {
$always();

Expand Down Expand Up @@ -256,7 +256,7 @@ public function await(): mixed
* @param null|Throwable $error
* @param null|T $value
*/
static function (?Throwable $error, mixed $value) use ($suspension): void {
static function (null|Throwable $error, mixed $value) use ($suspension): void {
if ($error) {
$suspension->throw($error);
} else {
Expand Down
8 changes: 6 additions & 2 deletions src/Psl/Async/Exception/CompositeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class CompositeException extends Exception implements ExceptionInterface
* @param non-empty-array<array-key, Throwable> $reasons Array of exceptions.
* @param string|null $message Exception message, defaults to message generated from passed exceptions.
*/
public function __construct(array $reasons, ?string $message = null)
public function __construct(array $reasons, null|string $message = null)
{
parent::__construct($message ?? $this->generateMessage($reasons));

Expand All @@ -43,7 +43,11 @@ public function getReasons(): array
*/
private function generateMessage(array $reasons): string
{
$message = Str\format('"Multiple errors encountered (%d); use "%s::getReasons()" to retrieve the array of exceptions thrown:', count($reasons), self::class);
$message = Str\format(
'"Multiple errors encountered (%d); use "%s::getReasons()" to retrieve the array of exceptions thrown:',
count($reasons),
self::class,
);

foreach ($reasons as $reason) {
$message .= PHP_EOL . PHP_EOL . $reason::class;
Expand Down
7 changes: 5 additions & 2 deletions src/Psl/Async/Exception/UnhandledAwaitableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ final class UnhandledAwaitableException extends RuntimeException implements Exce
public static function forThrowable(Throwable $throwable): UnhandledAwaitableException
{
return new self(
Str\format('Unhandled awaitable error "%s", make sure to call `Awaitable::await()` before the awaitable is destroyed, or call `Awaitable::ignore()` to ignore exceptions.', $throwable::class),
Str\format(
'Unhandled awaitable error "%s", make sure to call `Awaitable::await()` before the awaitable is destroyed, or call `Awaitable::ignore()` to ignore exceptions.',
$throwable::class,
),
(int) $throwable->getCode(),
$throwable
$throwable,
);
}
}
19 changes: 6 additions & 13 deletions src/Psl/Async/Internal/AwaitableIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class AwaitableIterator
/**
* @var null|Awaitable<void>|Awaitable<null>|Awaitable<array{Tk, Awaitable<Tv>}>
*/
private ?Awaitable $complete = null;
private null|Awaitable $complete = null;

public function __construct()
{
Expand All @@ -58,20 +58,13 @@ public function enqueue(State $state, mixed $key, Awaitable $awaitable): void
Psl\invariant_violation('Iterator has already been marked as complete');
}

$queue = $this->queue; // Using separate object to avoid a circular reference.
$queue =
$this->queue; // Using separate object to avoid a circular reference.
$id = $state->subscribe(
/**
* @param Tv|null $_result
*/
static function (
?Throwable $_error,
mixed $_result,
string $id
) use (
$key,
$awaitable,
$queue
): void {
static function (null|Throwable $_error, mixed $_result, string $id) use ($key, $awaitable, $queue): void {
unset($queue->pending[$id]);

if ($queue->suspension) {
Expand All @@ -81,7 +74,7 @@ static function (
}

$queue->items[] = [$key, $awaitable];
}
},
);

$queue->pending[$id] = $state;
Expand Down Expand Up @@ -126,7 +119,7 @@ public function error(Throwable $exception): void
*
* @return null|array{0: Tk, 1: Awaitable<Tv>}
*/
public function consume(): ?array
public function consume(): null|array
{
if (null !== $this->queue->suspension) {
Psl\invariant_violation('Concurrent consume() operations are not supported');
Expand Down
2 changes: 1 addition & 1 deletion src/Psl/Async/Internal/AwaitableIteratorQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ final class AwaitableIteratorQueue
*/
public array $pending = [];

public ?Suspension $suspension = null;
public null|Suspension $suspension = null;
}
2 changes: 1 addition & 1 deletion src/Psl/Async/Internal/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ final class State
*/
private mixed $result = null;

private ?Throwable $throwable = null;
private null|Throwable $throwable = null;

/**
* @throws Exception\UnhandledAwaitableException
Expand Down
6 changes: 3 additions & 3 deletions src/Psl/Async/OptionalIncrementalTimeout.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class OptionalIncrementalTimeout
/**
* @var ?Timestamp The end time.
*/
private ?Timestamp $end;
private null|Timestamp $end;

/**
* @var (Closure(): ?Duration) The handler to be called upon timeout.
Expand All @@ -35,7 +35,7 @@ final class OptionalIncrementalTimeout
* @param null|Duration $timeout The timeout duration. Null to disable timeout.
* @param (Closure(): ?Duration) $handler The handler to be executed if the timeout is reached.
*/
public function __construct(?Duration $timeout, Closure $handler)
public function __construct(null|Duration $timeout, Closure $handler)
{
$this->handler = $handler;

Expand All @@ -59,7 +59,7 @@ public function __construct(?Duration $timeout, Closure $handler)
*
* @return Duration|null The remaining time duration, null if no timeout is set, or the handler's return value if the timeout is exceeded.
*/
public function getRemaining(): ?Duration
public function getRemaining(): null|Duration
{
if ($this->end === null) {
return null;
Expand Down
1 change: 0 additions & 1 deletion src/Psl/Async/Scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ public static function repeat(DateTime\Duration $interval, Closure $callback): s
return EventLoop::repeat($interval->getTotalSeconds(), $callback);
}


/**
* Enable a callback to be active starting in the next tick.
*
Expand Down
5 changes: 4 additions & 1 deletion src/Psl/Async/all.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ function all(iterable $awaitables): array
throw $exception;
}

throw new Exception\CompositeException([$exception, ...$errors], 'Multiple exceptions thrown while waiting.');
throw new Exception\CompositeException(
[$exception, ...$errors],
'Multiple exceptions thrown while waiting.',
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Psl/Async/later.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function later(): void
{
$suspension = EventLoop::getSuspension();

EventLoop::defer(static fn () => $suspension->resume());
EventLoop::defer(static fn() => $suspension->resume());

$suspension->suspend();
}
5 changes: 1 addition & 4 deletions src/Psl/Async/sleep.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
function sleep(DateTime\Duration $duration): void
{
$suspension = EventLoop::getSuspension();
$watcher = EventLoop::delay(
$duration->getTotalSeconds(),
static fn () => $suspension->resume(),
);
$watcher = EventLoop::delay($duration->getTotalSeconds(), static fn() => $suspension->resume());

try {
$suspension->suspend();
Expand Down
2 changes: 1 addition & 1 deletion src/Psl/Channel/ChannelInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface ChannelInterface extends Countable
*
* @psalm-mutation-free
*/
public function getCapacity(): ?int;
public function getCapacity(): null|int;

/**
* Closes the channel.
Expand Down
2 changes: 1 addition & 1 deletion src/Psl/Channel/Internal/ChannelSideTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ trait ChannelSideTrait
*
* @psalm-mutation-free
*/
public function getCapacity(): ?int
public function getCapacity(): null|int
{
/** @var null|int<1, max> */
return $this->state->getCapacity();
Expand Down
2 changes: 1 addition & 1 deletion src/Psl/Collection/AccessibleCollectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public function dropWhile(Closure $fn): AccessibleCollectionInterface;
*
* @psalm-mutation-free
*/
public function slice(int $start, ?int $length = null): AccessibleCollectionInterface;
public function slice(int $start, null|int $length = null): AccessibleCollectionInterface;

/**
* Returns a `AccessibleCollectionInterface` containing the original `AccessibleCollectionInterface` split into
Expand Down
2 changes: 1 addition & 1 deletion src/Psl/Collection/CollectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public function dropWhile(Closure $fn): CollectionInterface;
*
* @psalm-mutation-free
*/
public function slice(int $start, ?int $length = null): CollectionInterface;
public function slice(int $start, null|int $length = null): CollectionInterface;

/**
* Returns a `CollectionInterface` containing the original `CollectionInterface` split into
Expand Down
8 changes: 3 additions & 5 deletions src/Psl/Collection/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ public function get(int|string $k): mixed
return $this->elements[$k] ?? null;
}


/**
* Returns a `Vector` containing the values of the current
* `Map`.
Expand Down Expand Up @@ -532,7 +531,7 @@ public function dropWhile(Closure $fn): Map
*
* @psalm-mutation-free
*/
public function slice(int $start, ?int $length = null): Map
public function slice(int $start, null|int $length = null): Map
{
/** @psalm-suppress ImpureFunctionCall - conditionally pure */
$result = Dict\slice($this->elements, $start, $length);
Expand All @@ -555,8 +554,7 @@ public function slice(int $start, ?int $length = null): Map
public function chunk(int $size): Vector
{
/** @psalm-suppress ImpureMethodCall */
return $this
->zip($this->keys()->toArray())
return $this->zip($this->keys()->toArray())
->values()
->chunk($size)
->map(
Expand All @@ -575,7 +573,7 @@ static function (Vector $vector): Map {
}

return Map::fromArray($array);
}
},
);
}
}
2 changes: 1 addition & 1 deletion src/Psl/Collection/MapInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public function dropWhile(Closure $fn): MapInterface;
*
* @psalm-mutation-free
*/
public function slice(int $start, ?int $length = null): MapInterface;
public function slice(int $start, null|int $length = null): MapInterface;

/**
* Returns a `VectorInterface` containing the original `MapInterface` split into
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public function dropWhile(Closure $fn): MutableAccessibleCollectionInterface;
*
* @psalm-mutation-free
*/
public function slice(int $start, ?int $length = null): MutableAccessibleCollectionInterface;
public function slice(int $start, null|int $length = null): MutableAccessibleCollectionInterface;

/**
* Returns a `MutableAccessibleCollectionInterface` containing the original `MutableAccessibleCollectionInterface` split into
Expand Down
2 changes: 1 addition & 1 deletion src/Psl/Collection/MutableCollectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function dropWhile(Closure $fn): MutableCollectionInterface;
*
* @psalm-mutation-free
*/
public function slice(int $start, ?int $length = null): MutableCollectionInterface;
public function slice(int $start, null|int $length = null): MutableCollectionInterface;

/**
* Returns a `MutableCollectionInterface` containing the original `MutableCollectionInterface` split into
Expand Down
23 changes: 15 additions & 8 deletions src/Psl/Collection/MutableMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ public function dropWhile(Closure $fn): MutableMap
*
* @psalm-mutation-free
*/
public function slice(int $start, ?int $length = null): MutableMap
public function slice(int $start, null|int $length = null): MutableMap
{
/** @psalm-suppress ImpureFunctionCall - conditionally pure */
return self::fromArray(Dict\slice($this->elements, $start, $length));
Expand All @@ -560,8 +560,7 @@ public function slice(int $start, ?int $length = null): MutableMap
public function chunk(int $size): MutableVector
{
/** @psalm-suppress ImpureMethodCall */
return $this
->zip($this->keys()->toArray())
return $this->zip($this->keys()->toArray())
->values()
->chunk($size)
->map(
Expand All @@ -580,7 +579,7 @@ static function (MutableVector $vector): MutableMap {
}

return MutableMap::fromArray($array);
}
},
);
}

Expand Down Expand Up @@ -730,7 +729,9 @@ public function clear(): MutableMap
public function offsetExists(mixed $offset): bool
{
if (!is_int($offset) && !is_string($offset)) {
throw new Exception\InvalidOffsetException('Invalid map read offset type, expected a string or an integer.');
throw new Exception\InvalidOffsetException(
'Invalid map read offset type, expected a string or an integer.',
);
}

/** @var Tk $offset - technically, we don't know if the offset is of type Tk, but we can assume it is, as this causes no "harm". */
Expand All @@ -754,7 +755,9 @@ public function offsetExists(mixed $offset): bool
public function offsetGet(mixed $offset): mixed
{
if (!is_int($offset) && !is_string($offset)) {
throw new Exception\InvalidOffsetException('Invalid map read offset type, expected a string or an integer.');
throw new Exception\InvalidOffsetException(
'Invalid map read offset type, expected a string or an integer.',
);
}

/** @var Tk $offset - technically, we don't know if the offset is of type Tk, but we can assume it is, as this causes no "harm". */
Expand All @@ -777,7 +780,9 @@ public function offsetGet(mixed $offset): mixed
public function offsetSet(mixed $offset, mixed $value): void
{
if (!is_int($offset) && !is_string($offset)) {
throw new Exception\InvalidOffsetException('Invalid map write offset type, expected a string or an integer.');
throw new Exception\InvalidOffsetException(
'Invalid map write offset type, expected a string or an integer.',
);
}

/** @var Tk $offset - technically, we don't know if the offset is of type Tk, but we can assume it is, as this causes no "harm". */
Expand All @@ -798,7 +803,9 @@ public function offsetSet(mixed $offset, mixed $value): void
public function offsetUnset(mixed $offset): void
{
if (!is_int($offset) && !is_string($offset)) {
throw new Exception\InvalidOffsetException('Invalid map read offset type, expected a string or an integer.');
throw new Exception\InvalidOffsetException(
'Invalid map read offset type, expected a string or an integer.',
);
}

/** @var Tk $offset - technically, we don't know if the offset is of type Tk, but we can assume it is, as this causes no "harm". */
Expand Down
2 changes: 1 addition & 1 deletion src/Psl/Collection/MutableMapInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public function dropWhile(Closure $fn): MutableMapInterface;
*
* @psalm-mutation-free
*/
public function slice(int $start, ?int $length = null): MutableMapInterface;
public function slice(int $start, null|int $length = null): MutableMapInterface;

/**
* Returns a `MutableVectorInterface` containing the original `MutableMapInterface` split into
Expand Down
Loading

0 comments on commit 84a0994

Please sign in to comment.