diff --git a/composer.json b/composer.json index c8a602ee..8b4bdf03 100644 --- a/composer.json +++ b/composer.json @@ -62,7 +62,7 @@ "scripts": { "lint": "php-cs-fixer fix -v", "test:lint": "php-cs-fixer fix -v --dry-run", - "test:types": "phpstan analyse --ansi --memory-limit=-1", + "test:types": "phpstan analyse --ansi --memory-limit=-1 --debug", "test:unit": "php bin/pest --colors=always --exclude-group=integration", "test:parallel": "exit 1", "test:integration": "exit 1", diff --git a/phpstan.neon b/phpstan.neon index d5dc4ef6..c1a0e56e 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -4,7 +4,7 @@ includes: - vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon parameters: - level: max + level: 5 paths: - src diff --git a/src/Datasets.php b/src/Datasets.php index 0cf59d60..429de157 100644 --- a/src/Datasets.php +++ b/src/Datasets.php @@ -129,7 +129,7 @@ final class Datasets $processedDataset = []; if (is_string($data)) { - if (! array_key_exists($data, self::$datasets)) { + if (!array_key_exists($data, self::$datasets)) { throw new DatasetDoesNotExist($data); } diff --git a/src/Expectation.php b/src/Expectation.php index 28ea26af..920a5f70 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -74,11 +74,9 @@ final class Expectation /** * Dump the expectation value and end the script. * - * @param mixed $arguments - * * @return never */ - public function dd(...$arguments): void + public function dd(mixed ...$arguments): void { if (function_exists('dd')) { dd($this->value, ...$arguments); @@ -91,13 +89,10 @@ final class Expectation /** * Send the expectation value to Ray along with all given arguments. - * - * @param ...mixed $arguments */ public function ray(mixed ...$arguments): self { if (function_exists('ray')) { - // @phpstan-ignore-next-line ray($this->value, ...$arguments); } @@ -224,7 +219,7 @@ final class Expectation $condition = is_callable($condition) ? $condition : static function () use ($condition): bool { - return $condition; // @phpstan-ignore-line + return $condition; }; return $this->when(!$condition(), $callback); @@ -241,7 +236,7 @@ final class Expectation $condition = is_callable($condition) ? $condition : static function () use ($condition): bool { - return $condition; // @phpstan-ignore-line + return $condition; }; if ($condition()) { @@ -371,6 +366,8 @@ final class Expectation /** * Asserts that the value starts with $expected. + * + * @param non-empty-string $expected */ public function toStartWith(string $expected): Expectation { @@ -381,6 +378,8 @@ final class Expectation /** * Asserts that the value ends with $expected. + * + * @param non-empty-string $expected */ public function toEndWith(string $expected): Expectation { @@ -526,7 +525,6 @@ final class Expectation */ public function toBeInstanceOf(string $class): Expectation { - /* @phpstan-ignore-next-line */ Assert::assertInstanceOf($class, $this->value); return $this; diff --git a/src/Factories/TestCaseFactory.php b/src/Factories/TestCaseFactory.php index 8882a0da..d21b5513 100644 --- a/src/Factories/TestCaseFactory.php +++ b/src/Factories/TestCaseFactory.php @@ -71,11 +71,13 @@ final class TestCaseFactory public function make(): void { - $methods = array_filter($this->methods, function ($method) { - return count($onlyTestCases = $this->methodsUsingOnly()) === 0 || in_array($method, $onlyTestCases, true); + $methodsUsingOnly = $this->methodsUsingOnly(); + + $methods = array_filter($this->methods, function ($method) use ($methodsUsingOnly) { + return count($methodsUsingOnly) === 0 || in_array($method, $methodsUsingOnly, true); }); - if (count($this->methods) > 0) { + if (count($methods) > 0) { $this->evaluate($this->filename, $methods); } } @@ -91,7 +93,7 @@ final class TestCaseFactory return []; } - return array_filter($this->methods, static fn ($method): bool => $method->only); + return array_values(array_filter($this->methods, static fn ($method): bool => $method->only)); } /** @@ -147,7 +149,7 @@ final class TestCaseFactory $annotations = (new $annotation())->add($method, $annotations); } - if (!empty($method->datasets)) { + if (count($method->datasets) > 0) { $dataProviderName = $methodName . '_dataset'; $annotations[] = "@dataProvider $dataProviderName"; @@ -214,7 +216,7 @@ EOF; throw ShouldNotHappen::fromMessage('The test description may not be empty.'); } - if (isset($this->methods[$method->description])) { + if (array_key_exists($method->description, $this->methods)) { throw new TestAlreadyExist($method->filename, $method->description); } diff --git a/src/Factories/TestCaseMethodFactory.php b/src/Factories/TestCaseMethodFactory.php index 1c16d5f6..ffa4cb4b 100644 --- a/src/Factories/TestCaseMethodFactory.php +++ b/src/Factories/TestCaseMethodFactory.php @@ -81,7 +81,7 @@ final class TestCaseMethodFactory $method = $this; return function () use ($testCase, $method, $closure): mixed { // @phpstan-ignore-line - /** @var TestCase $this */ + /* @var TestCase $this */ $testCase->proxies->proxy($this); $method->proxies->proxy($this); diff --git a/src/Logging/JUnit.php b/src/Logging/JUnit.php index 91921b31..207912ac 100644 --- a/src/Logging/JUnit.php +++ b/src/Logging/JUnit.php @@ -12,29 +12,7 @@ declare(strict_types=1); namespace Pest\Logging; -use function class_exists; -use DOMDocument; -use DOMElement; -use Exception; -use function method_exists; -use Pest\Concerns\Testable; -use PHPUnit\Framework\AssertionFailedError; -use PHPUnit\Framework\ExceptionWrapper; -use PHPUnit\Framework\SelfDescribing; -use PHPUnit\Framework\Test; -use PHPUnit\Framework\TestFailure; -use PHPUnit\Framework\TestListener; -use PHPUnit\Framework\TestSuite; -use PHPUnit\Framework\Warning; -use PHPUnit\Util\Filter; use PHPUnit\Util\Printer; -use PHPUnit\Util\Xml; -use ReflectionClass; -use ReflectionException; -use function sprintf; -use function str_replace; -use Throwable; -use function trim; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit diff --git a/src/OppositeExpectation.php b/src/OppositeExpectation.php index e56eabd3..e4ec3d85 100644 --- a/src/OppositeExpectation.php +++ b/src/OppositeExpectation.php @@ -69,9 +69,8 @@ final class OppositeExpectation public function __get(string $name): Expectation { try { - /** @throws ExpectationFailedException */ $this->original->{$name}; // @phpstan-ignore-line - } catch (ExpectationFailedException) { + } catch (ExpectationFailedException) { // @phpstan-ignore-line return $this->original; } diff --git a/src/Repositories/TestRepository.php b/src/Repositories/TestRepository.php index 5ab98700..b8e2b53e 100644 --- a/src/Repositories/TestRepository.php +++ b/src/Repositories/TestRepository.php @@ -90,7 +90,7 @@ final class TestRepository */ public function set(TestCaseMethodFactory $method): void { - if (! array_key_exists($method->filename, $this->testCases)) { + if (!array_key_exists($method->filename, $this->testCases)) { $this->testCases[$method->filename] = new TestCaseFactory($method->filename); } diff --git a/src/Support/ChainableClosure.php b/src/Support/ChainableClosure.php index b37e4f5f..8a136682 100644 --- a/src/Support/ChainableClosure.php +++ b/src/Support/ChainableClosure.php @@ -6,7 +6,6 @@ namespace Pest\Support; use Closure; use Pest\Exceptions\ShouldNotHappen; -use PHPUnit\Framework\TestCase; /** * @internal @@ -19,7 +18,7 @@ final class ChainableClosure public static function from(Closure $closure, Closure $next): Closure { return function () use ($closure, $next): void { - if (! is_object($this)) { // @phpstan-ignore-line + if (!is_object($this)) { // @phpstan-ignore-line throw ShouldNotHappen::fromMessage('$this not bound to chainable closure.'); } diff --git a/src/Support/HigherOrderTapProxy.php b/src/Support/HigherOrderTapProxy.php index bfce21c8..9bcfb479 100644 --- a/src/Support/HigherOrderTapProxy.php +++ b/src/Support/HigherOrderTapProxy.php @@ -13,7 +13,7 @@ use Throwable; */ final class HigherOrderTapProxy { - private const UNDEFINED_PROPERTY = 'Undefined property: P\\'; + private const UNDEFINED_PROPERTY = 'Undefined property: P\\'; // @phpstan-ignore-line /** * Create a new tap proxy instance. @@ -42,9 +42,8 @@ final class HigherOrderTapProxy public function __get(string $property) { try { - /** @throws Throwable */ return $this->target->{$property}; // @phpstan-ignore-line - } catch (Throwable $throwable) { + } catch (Throwable $throwable) { // @phpstan-ignore-line Reflection::setPropertyValue($throwable, 'file', Backtrace::file()); Reflection::setPropertyValue($throwable, 'line', Backtrace::line());