diff --git a/src/Configuration.php b/src/Configuration.php index 4261f3ef..35a32ff0 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -33,7 +33,7 @@ final readonly class Configuration */ public function in(string ...$targets): UsesCall { - return (new UsesCall($this->filename, []))->in(...$targets); + return new UsesCall($this->filename, [])->in(...$targets); } /** @@ -60,7 +60,7 @@ final readonly class Configuration */ public function group(string ...$groups): UsesCall { - return (new UsesCall($this->filename, []))->group(...$groups); + return new UsesCall($this->filename, [])->group(...$groups); } /** @@ -68,7 +68,7 @@ final readonly class Configuration */ public function only(): void { - (new BeforeEachCall(TestSuite::getInstance(), $this->filename))->only(); + new BeforeEachCall(TestSuite::getInstance(), $this->filename)->only(); } /** diff --git a/src/Expectation.php b/src/Expectation.php index 50729d7a..2fbbc1ee 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -237,7 +237,7 @@ final class Expectation if ($callbacks[$index] instanceof Closure) { $callbacks[$index](new self($value), new self($key)); } else { - (new self($value))->toEqual($callbacks[$index]); + new self($value)->toEqual($callbacks[$index]); } $index = isset($callbacks[$index + 1]) ? $index + 1 : 0; @@ -864,15 +864,7 @@ final class Expectation return Targeted::make( $this, - function (ObjectDescription $object) use ($interfaces): bool { - foreach ($interfaces as $interface) { - if (! isset($object->reflectionClass) || ! $object->reflectionClass->implementsInterface($interface)) { - return false; - } - } - - return true; - }, + fn(ObjectDescription $object): bool => array_all($interfaces, fn($interface): bool => isset($object->reflectionClass) && $object->reflectionClass->implementsInterface($interface)), "to implement '".implode("', '", $interfaces)."'", FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')), ); @@ -1087,8 +1079,8 @@ final class Expectation $this, fn (ObjectDescription $object): bool => isset($object->reflectionClass) && $object->reflectionClass->isEnum() - && (new ReflectionEnum($object->name))->isBacked() // @phpstan-ignore-line - && (string) (new ReflectionEnum($object->name))->getBackingType() === $backingType, // @phpstan-ignore-line + && new ReflectionEnum($object->name)->isBacked() // @phpstan-ignore-line + && (string) new ReflectionEnum($object->name)->getBackingType() === $backingType, // @phpstan-ignore-line 'to be '.$backingType.' backed enum', FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')), ); diff --git a/src/Expectations/OppositeExpectation.php b/src/Expectations/OppositeExpectation.php index 2713c724..9de449c8 100644 --- a/src/Expectations/OppositeExpectation.php +++ b/src/Expectations/OppositeExpectation.php @@ -576,15 +576,7 @@ final readonly class OppositeExpectation return Targeted::make( $original, - function (ObjectDescription $object) use ($traits): bool { - foreach ($traits as $trait) { - if (isset($object->reflectionClass) && in_array($trait, $object->reflectionClass->getTraitNames(), true)) { - return false; - } - } - - return true; - }, + fn(ObjectDescription $object): bool => array_all($traits, fn($trait): bool => !(isset($object->reflectionClass) && in_array($trait, $object->reflectionClass->getTraitNames(), true))), "not to use traits '".implode("', '", $traits)."'", FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')), ); @@ -604,15 +596,7 @@ final readonly class OppositeExpectation return Targeted::make( $original, - function (ObjectDescription $object) use ($interfaces): bool { - foreach ($interfaces as $interface) { - if (isset($object->reflectionClass) && $object->reflectionClass->implementsInterface($interface)) { - return false; - } - } - - return true; - }, + fn(ObjectDescription $object): bool => array_all($interfaces, fn($interface): bool => !(isset($object->reflectionClass) && $object->reflectionClass->implementsInterface($interface))), "not to implement '".implode("', '", $interfaces)."'", FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')), ); @@ -852,8 +836,8 @@ final readonly class OppositeExpectation $original, fn (ObjectDescription $object): bool => isset($object->reflectionClass) === false || ! $object->reflectionClass->isEnum() - || ! (new \ReflectionEnum($object->name))->isBacked() // @phpstan-ignore-line - || (string) (new \ReflectionEnum($object->name))->getBackingType() !== $backingType, // @phpstan-ignore-line + || ! new \ReflectionEnum($object->name)->isBacked() // @phpstan-ignore-line + || (string) new \ReflectionEnum($object->name)->getBackingType() !== $backingType, // @phpstan-ignore-line 'not to be '.$backingType.' backed enum', FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')), ); diff --git a/src/Factories/TestCaseFactory.php b/src/Factories/TestCaseFactory.php index 0d2a0978..2978b9f1 100644 --- a/src/Factories/TestCaseFactory.php +++ b/src/Factories/TestCaseFactory.php @@ -191,7 +191,7 @@ final class TestCaseFactory if ( $method->closure instanceof \Closure && - (new \ReflectionFunction($method->closure))->isStatic() + new \ReflectionFunction($method->closure)->isStatic() ) { throw new TestClosureMustNotBeStatic($method); diff --git a/src/Mixins/Expectation.php b/src/Mixins/Expectation.php index 09974787..9ca9aef7 100644 --- a/src/Mixins/Expectation.php +++ b/src/Mixins/Expectation.php @@ -921,7 +921,7 @@ final class Expectation if ($exception instanceof Closure) { $callback = $exception; - $parameters = (new ReflectionFunction($exception))->getParameters(); + $parameters = new ReflectionFunction($exception)->getParameters(); if (count($parameters) !== 1) { throw new InvalidArgumentException('The given closure must have a single parameter type-hinted as the class string.'); diff --git a/src/PendingCalls/UsesCall.php b/src/PendingCalls/UsesCall.php index 04d8b83e..7acc1208 100644 --- a/src/PendingCalls/UsesCall.php +++ b/src/PendingCalls/UsesCall.php @@ -53,9 +53,7 @@ final class UsesCall $this->targets = [$filename]; } - /** - * @deprecated Use `pest()->printer()->compact()` instead. - */ + #[\Deprecated(message: 'Use `pest()->printer()->compact()` instead.')] public function compact(): self { DefaultPrinter::compact(true); diff --git a/src/Plugins/Parallel.php b/src/Plugins/Parallel.php index 94902823..5e13a430 100644 --- a/src/Plugins/Parallel.php +++ b/src/Plugins/Parallel.php @@ -175,14 +175,7 @@ final class Parallel implements HandlesArguments private function hasArgumentsThatWouldBeFasterWithoutParallel(): bool { $arguments = new ArgvInput; - - foreach (self::UNSUPPORTED_ARGUMENTS as $unsupportedArgument) { - if ($arguments->hasParameterOption($unsupportedArgument)) { - return true; - } - } - - return false; + return array_any(self::UNSUPPORTED_ARGUMENTS, fn(string|array $unsupportedArgument): bool => $arguments->hasParameterOption($unsupportedArgument)); } /** diff --git a/src/Plugins/Shard.php b/src/Plugins/Shard.php index f48260bb..afb2e764 100644 --- a/src/Plugins/Shard.php +++ b/src/Plugins/Shard.php @@ -83,11 +83,11 @@ final class Shard implements AddsOutput, HandlesArguments */ private function allTests(array $arguments): array { - $output = (new Process([ + $output = new Process([ 'php', ...$this->removeParallelArguments($arguments), '--list-tests', - ]))->mustRun()->getOutput(); + ])->mustRun()->getOutput(); preg_match_all('/ - (?:P\\\\)?(Tests\\\\[^:]+)::/', $output, $matches); diff --git a/src/Support/HigherOrderMessage.php b/src/Support/HigherOrderMessage.php index ce948244..e25dc633 100644 --- a/src/Support/HigherOrderMessage.php +++ b/src/Support/HigherOrderMessage.php @@ -50,7 +50,7 @@ final class HigherOrderMessage } if ($this->hasHigherOrderCallable()) { - return (new HigherOrderCallables($target))->{$this->name}(...$this->arguments); + return new HigherOrderCallables($target)->{$this->name}(...$this->arguments); } try { diff --git a/src/Support/HigherOrderMessageCollection.php b/src/Support/HigherOrderMessageCollection.php index 41245108..b90c257d 100644 --- a/src/Support/HigherOrderMessageCollection.php +++ b/src/Support/HigherOrderMessageCollection.php @@ -31,7 +31,7 @@ final class HigherOrderMessageCollection */ public function addWhen(callable $condition, string $filename, int $line, string $name, ?array $arguments): void { - $this->messages[] = (new HigherOrderMessage($filename, $line, $name, $arguments))->when($condition); + $this->messages[] = new HigherOrderMessage($filename, $line, $name, $arguments)->when($condition); } /** diff --git a/src/Support/HigherOrderTapProxy.php b/src/Support/HigherOrderTapProxy.php index 60e65bac..166d8a42 100644 --- a/src/Support/HigherOrderTapProxy.php +++ b/src/Support/HigherOrderTapProxy.php @@ -38,7 +38,7 @@ final class HigherOrderTapProxy return $this->target->{$property}; } - $className = (new ReflectionClass($this->target))->getName(); + $className = new ReflectionClass($this->target)->getName(); if (str_starts_with($className, 'P\\')) { $className = substr($className, 2); @@ -60,7 +60,7 @@ final class HigherOrderTapProxy $filename = Backtrace::file(); $line = Backtrace::line(); - return (new HigherOrderMessage($filename, $line, $methodName, $arguments)) + return new HigherOrderMessage($filename, $line, $methodName, $arguments) ->call($this->target); } } diff --git a/src/Support/Reflection.php b/src/Support/Reflection.php index d4f5f133..da7a13b2 100644 --- a/src/Support/Reflection.php +++ b/src/Support/Reflection.php @@ -180,7 +180,7 @@ final class Reflection */ public static function getFunctionArguments(Closure $function): array { - $parameters = (new ReflectionFunction($function))->getParameters(); + $parameters = new ReflectionFunction($function)->getParameters(); $arguments = []; foreach ($parameters as $parameter) { @@ -206,7 +206,7 @@ final class Reflection public static function getFunctionVariable(Closure $function, string $key): mixed { - return (new ReflectionFunction($function))->getStaticVariables()[$key] ?? null; + return new ReflectionFunction($function)->getStaticVariables()[$key] ?? null; } /**