refacto(phpstan-to-8): few adjustments

This commit is contained in:
Nuno Maduro
2021-11-18 23:39:37 +00:00
committed by Fabio Ivona
parent 0b5cea6df1
commit 86dca12c09
18 changed files with 107 additions and 94 deletions

View File

@ -12,7 +12,7 @@ final class Arr
/**
* Checks if the given array has the given key.
*
* @param array<mixed> $array
* @param array<array-key, mixed> $array
*/
public static function has(array $array, string|int $key): bool
{
@ -36,7 +36,7 @@ final class Arr
/**
* Gets the given key value.
*
* @param array<mixed> $array
* @param array<array-key, mixed> $array
*/
public static function get(array $array, string|int $key, mixed $default = null): mixed
{

View File

@ -22,8 +22,8 @@ final class ChainableClosure
throw ShouldNotHappen::fromMessage('$this not bound to chainable closure.');
}
\Pest\Support\Closure::safeBind($closure, $this, $this::class)(...func_get_args());
\Pest\Support\Closure::safeBind($next, $this, $this::class)(...func_get_args());
\Pest\Support\Closure::bind($closure, $this, $this::class)(...func_get_args());
\Pest\Support\Closure::bind($next, $this, $this::class)(...func_get_args());
};
}
@ -33,8 +33,8 @@ final class ChainableClosure
public static function fromStatic(Closure $closure, Closure $next): Closure
{
return static function () use ($closure, $next): void {
\Pest\Support\Closure::safeBind($closure, null, self::class)(...func_get_args());
\Pest\Support\Closure::safeBind($next, null, self::class)(...func_get_args());
\Pest\Support\Closure::bind($closure, null, self::class)(...func_get_args());
\Pest\Support\Closure::bind($next, null, self::class)(...func_get_args());
};
}
}

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Pest\Support;
use Closure as BaseClosure;
use Pest\Exceptions\ShouldNotHappen;
/**
@ -11,13 +12,20 @@ use Pest\Exceptions\ShouldNotHappen;
*/
final class Closure
{
public static function safeBind(\Closure|null $closure, ?object $newThis, object|string|null $newScope = 'static'): \Closure
/**
* Binds the given closure to the given "this".
*
* @return BaseClosure|never
*
* @throws ShouldNotHappen
*/
public static function bind(BaseClosure|null $closure, ?object $newThis, object|string|null $newScope = 'static'): BaseClosure
{
if ($closure == null) {
throw ShouldNotHappen::fromMessage('Could not bind null closure.');
}
$closure = \Closure::bind($closure, $newThis, $newScope);
$closure = BaseClosure::bind($closure, $newThis, $newScope);
if ($closure == false) {
throw ShouldNotHappen::fromMessage('Could not bind closure.');

View File

@ -51,7 +51,7 @@ final class ExceptionTrace
$property = new ReflectionProperty($t, 'serializableTrace');
$property->setAccessible(true);
/** @var array<array<string>> $trace */
/** @var array<int, array<string, string>> $trace */
$trace = $property->getValue($t);
$cleanedTrace = [];

View File

@ -25,7 +25,7 @@ final class HigherOrderCallables
*
* Create a new expectation. Callable values will be executed prior to returning the new expectation.
*
* @param (callable():TValue)|TValue $value
* @param (Closure():TValue)|TValue $value
*
* @return Expectation<TValue>
*/