Skip to content

Commit

Permalink
Fix phpstan!
Browse files Browse the repository at this point in the history
  • Loading branch information
VennDev authored Sep 2, 2024
1 parent fea88a0 commit 14ddb45
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/vennv/vapm/ClosureThread.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ final class ClosureThread extends Thread implements ClosureThreadInterface
private mixed $callback;

/**
* @var array<int, mixed>
* @phpstan-var array<int, mixed>
* @var array<int|float|array|object|null, mixed>
* @phpstan-var array<int|float|array|object|null, mixed>
*/
private array $argsCallback = [];

/**
* @param callable $callback
* @param array<int|float|array|object|null, mixed> $args
*/
public function __construct(callable $callback, array $args = [])
{
$this->callback = $callback;
Expand All @@ -65,6 +69,7 @@ public function __construct(callable $callback, array $args = [])

public function onRun(): void
{
/** @phpstan-ignore-next-line */
if (is_callable($this->callback)) {

Check failure on line 73 in src/vennv/vapm/ClosureThread.php

View workflow job for this annotation

GitHub Actions / Jobs (8.2)

No error to ignore is reported on line 73.
$callback = call_user_func($this->callback, ...$this->argsCallback);
if ($callback instanceof Generator) {
Expand Down
10 changes: 9 additions & 1 deletion src/vennv/vapm/Work.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ interface WorkInterface

/**
* @param callable $work
* @param array<int|float|array|object|null, mixed> $args
* @return void
*
* The work is a function that will be executed when the work is run.
*/
public function add(callable $work): void;
public function add(callable $work, array $args = []): void;

/**
* @param int $index
Expand Down Expand Up @@ -107,6 +108,13 @@ public function __construct()
$this->queue = new SplQueue();
}

/**
* @param callable $work
* @param array<int|float|array|object|null, mixed> $args
* @return void
*
* Add a work to the work list.
*/
public function add(callable $work, array $args = []): void
{
$this->queue->enqueue(new ClosureThread($work, $args));
Expand Down
4 changes: 3 additions & 1 deletion src/vennv/vapm/utils/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
use ReflectionException;
use ReflectionFunction;
use SplFileInfo;
use Throwable;
use RuntimeException;
use function array_slice;
use function file;
use function implode;
Expand Down Expand Up @@ -404,10 +404,12 @@ public static function toStringAny(mixed $data): array
} elseif (is_null($data)) {
return [$type => 'null'];
} elseif (is_callable($data)) {
/** @phpstan-ignore-next-line */
return ['callable' => self::closureToStringSafe($data)];
} elseif (is_string($data)) {
return [$type => '\'' . $data . '\''];
}
/** @phpstan-ignore-next-line */
return [$type => (string) $data];
}

Expand Down

0 comments on commit 14ddb45

Please sign in to comment.