mirror of
https://github.com/pestphp/pest.git
synced 2026-03-09 09:17:23 +01:00
Code quality improvements
This commit is contained in:
@ -35,16 +35,14 @@ trait Pipeable
|
||||
public function intercept(string $name, string|Closure $filter, Closure $handler): void
|
||||
{
|
||||
if (is_string($filter)) {
|
||||
$filter = function ($value) use ($filter): bool {
|
||||
return $value instanceof $filter;
|
||||
};
|
||||
$filter = fn ($value): bool => $value instanceof $filter;
|
||||
}
|
||||
|
||||
$this->pipe($name, function ($next, ...$arguments) use ($handler, $filter) {
|
||||
$this->pipe($name, function ($next, ...$arguments) use ($handler, $filter): void {
|
||||
/* @phpstan-ignore-next-line */
|
||||
if ($filter($this->value, ...$arguments)) {
|
||||
// @phpstan-ignore-next-line
|
||||
$handler->bindTo($this, get_class($this))(...$arguments);
|
||||
$handler->bindTo($this, $this::class)(...$arguments);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ trait Testable
|
||||
*/
|
||||
public function __addBeforeAll(?Closure $hook): void
|
||||
{
|
||||
if (! $hook) {
|
||||
if ($hook === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ trait Testable
|
||||
*/
|
||||
public function __addAfterAll(?Closure $hook): void
|
||||
{
|
||||
if (! $hook) {
|
||||
if ($hook === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -123,7 +123,7 @@ trait Testable
|
||||
*/
|
||||
private function __addHook(string $property, ?Closure $hook): void
|
||||
{
|
||||
if (! $hook) {
|
||||
if ($hook === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -221,11 +221,7 @@ trait Testable
|
||||
{
|
||||
$method = TestSuite::getInstance()->tests->get(self::$__filename)->getMethod($this->name());
|
||||
|
||||
if ($this->dataName()) {
|
||||
self::$__description = $method->description.' with '.$this->dataName();
|
||||
} else {
|
||||
self::$__description = $method->description;
|
||||
}
|
||||
self::$__description = $this->dataName() ? $method->description.' with '.$this->dataName() : $method->description;
|
||||
|
||||
if (count($arguments) !== 1) {
|
||||
return $arguments;
|
||||
@ -238,13 +234,15 @@ trait Testable
|
||||
$underlyingTest = Reflection::getFunctionVariable($this->__test, 'closure');
|
||||
$testParameterTypes = array_values(Reflection::getFunctionArguments($underlyingTest));
|
||||
|
||||
if (in_array($testParameterTypes[0], ['Closure', 'callable'])) {
|
||||
if (in_array($testParameterTypes[0], [\Closure::class, 'callable'])) {
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
$boundDatasetResult = $this->__callClosure($arguments[0], []);
|
||||
|
||||
if (count($testParameterTypes) === 1 || ! is_array($boundDatasetResult)) {
|
||||
if (count($testParameterTypes) === 1) {
|
||||
return [$boundDatasetResult];
|
||||
}
|
||||
if (! is_array($boundDatasetResult)) {
|
||||
return [$boundDatasetResult];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user