Skip to content

Commit

Permalink
Update Psalm and fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Dec 29, 2023
1 parent b6e3a6a commit 3de79a6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"require-dev": {
"amphp/php-cs-fixer-config": "^2",
"phpunit/phpunit": "^9",
"psalm/phar": "^5.4"
"psalm/phar": "^5.18"
},
"autoload": {
"psr-4": {
Expand Down
6 changes: 6 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,11 @@
<directory name="src" />
</errorLevel>
</MissingClosureReturnType>

<UnsupportedPropertyReferenceUsage>
<errorLevel type="suppress">
<directory name="src" />
</errorLevel>
</UnsupportedPropertyReferenceUsage>
</issueHandlers>
</psalm>
2 changes: 1 addition & 1 deletion src/Closable.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function close(): void;
/**
* Returns whether this resource has been closed.
*
* @return bool {@code true} if closed, otherwise {@code false}
* @return bool `true` if closed, otherwise `false`.
*/
public function isClosed(): bool;

Expand Down
14 changes: 11 additions & 3 deletions src/Internal/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@
/**
* Formats a stacktrace obtained via `debug_backtrace()`.
*
* @param list<array{args?:list<mixed>, class?: class-string, file: string, function: string, line: int, object?: object, type?: string}> $trace
* @param list<array{
* args?:list<mixed>,
* class?: class-string,
* file?: string,
* function: string,
* line?: int,
* object?: object,
* type?: string,
* }> $trace
* Output of `debug_backtrace()`.
*
* @return string Formatted stacktrace.
Expand All @@ -15,10 +23,10 @@
*/
function formatStacktrace(array $trace): string
{
return \implode("\n", \array_map(static function ($e, $i) {
return \implode("\n", \array_map(static function (array $e, int $i): string {
$line = "#{$i} ";

if (isset($e["file"])) {
if (isset($e["file"], $e['line'])) {
$line .= "{$e['file']}:{$e['line']} ";
}

Expand Down
19 changes: 9 additions & 10 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

namespace Amp;

use Amp\Internal\FutureState;
use Revolt\EventLoop;
use Revolt\EventLoop\UnsupportedFeatureException;

/**
* Creates a new fiber asynchronously using the given closure, returning a Future that is completed with the
* eventual return value of the passed function or will fail if the closure throws an exception.
* Creates a new fiber to execute the given closure asynchronously. A Future is returned which is completed with the
* return value of the passed closure or will fail if the closure throws an exception.
*
* @template T
*
* @param \Closure(...):T $closure
* @param \Closure(mixed...):T $closure
* @param mixed ...$args Arguments forwarded to the closure when starting the fiber.
*
* @return Future<T>
Expand All @@ -21,7 +20,7 @@ function async(\Closure $closure, mixed ...$args): Future
{
static $run = null;

$run ??= static function (FutureState $state, \Closure $closure, array $args): void {
$run ??= static function (Internal\FutureState $state, \Closure $closure, array $args): void {
$s = $state;
$c = $closure;

Expand All @@ -37,7 +36,7 @@ function async(\Closure $closure, mixed ...$args): Future
}
};

$state = new Internal\FutureState;
$state = new Internal\FutureState();

EventLoop::queue($run, $state, $closure, $args);

Expand Down Expand Up @@ -156,16 +155,16 @@ function weakClosure(\Closure $closure): \Closure
$closure = fn (mixed ...$args): mixed => $this->{$method}(...$args);
if ($useBindTo && $scope) {
$closure = $closure->bindTo(null, $scope->name);

if (!$closure) {
throw new \RuntimeException('Unable to rebind function to type ' . $scope->name);
}
}
} else {
// Rebind to remove reference to $that
$closure = $closure->bindTo(new \stdClass());
}

if (!$closure) {
throw new \RuntimeException('Unable to rebind function to type ' . ($scope?->name ?? $that::class));
}

$reference = \WeakReference::create($that);

/** @var \Closure(mixed...):TReturn */
Expand Down

0 comments on commit 3de79a6

Please sign in to comment.