diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index e7f03450..1f2b422c 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -52,6 +52,3 @@ jobs: - name: Style run: composer test:lint - - - name: Recfato - run: composer test:refacto diff --git a/composer.json b/composer.json index 14852736..35879005 100644 --- a/composer.json +++ b/composer.json @@ -56,8 +56,7 @@ "phpstan/phpstan": "^1.8.5", "phpstan/phpstan-strict-rules": "^1.4.3", "symfony/var-dumper": "^6.2.0", - "thecodingmachine/phpstan-strict-rules": "^1.0.0", - "rector/rector": "^0.14.2" + "thecodingmachine/phpstan-strict-rules": "^1.0.0" }, "minimum-stability": "dev", "prefer-stable": true, @@ -73,9 +72,7 @@ ], "scripts": { "lint": "pint --test", - "refactor": "rector", "test:lint": "pint --test", - "test:refactor": "rector --dry-run", "test:types": "phpstan analyse --ansi --memory-limit=-1 --debug", "test:unit": "php bin/pest --colors=always --exclude-group=integration", "test:parallel": "exit 1", @@ -85,8 +82,7 @@ "@test:lint", "@test:types", "@test:unit", - "@test:integration", - "@test:refactor" + "@test:integration" ] }, "extra": { diff --git a/src/Bootstrappers/BootFiles.php b/src/Bootstrappers/BootFiles.php index 6f8d2c02..f19aca40 100644 --- a/src/Bootstrappers/BootFiles.php +++ b/src/Bootstrappers/BootFiles.php @@ -63,8 +63,12 @@ final class BootFiles */ private function load(string $filename): void { - if (Str::endsWith($filename, '.php') && file_exists($filename)) { - include_once $filename; + if (! Str::endsWith($filename, '.php')) { + return; } + if (! file_exists($filename)) { + return; + } + include_once $filename; } } diff --git a/src/Bootstrappers/BootSubscribers.php b/src/Bootstrappers/BootSubscribers.php index f78dee18..5163b77c 100644 --- a/src/Bootstrappers/BootSubscribers.php +++ b/src/Bootstrappers/BootSubscribers.php @@ -17,7 +17,7 @@ final class BootSubscribers * * @var array> */ - private static array $subscribers = [ + private const SUBSCRIBERS = [ Subscribers\EnsureConfigurationIsValid::class, Subscribers\EnsureConfigurationDefaults::class, Subscribers\EnsureRetryRepositoryExists::class, @@ -29,7 +29,7 @@ final class BootSubscribers */ public function __invoke(): void { - foreach (self::$subscribers as $subscriber) { + foreach (self::SUBSCRIBERS as $subscriber) { Event\Facade::registerSubscriber( new $subscriber() ); diff --git a/src/Concerns/Pipeable.php b/src/Concerns/Pipeable.php index d1df162e..0a29d6a1 100644 --- a/src/Concerns/Pipeable.php +++ b/src/Concerns/Pipeable.php @@ -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; } diff --git a/src/Concerns/Testable.php b/src/Concerns/Testable.php index 9d20d895..e63c9a8e 100644 --- a/src/Concerns/Testable.php +++ b/src/Concerns/Testable.php @@ -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]; } diff --git a/src/ConfigLoader.php b/src/ConfigLoader.php index b2def1d2..870003c1 100644 --- a/src/ConfigLoader.php +++ b/src/ConfigLoader.php @@ -28,7 +28,7 @@ final class ConfigLoader /** * Creates a new instance of the config loader. */ - public function __construct(private string $rootPath) + public function __construct(private readonly string $rootPath) { $this->loadConfiguration(); } @@ -38,14 +38,14 @@ final class ConfigLoader */ public function getTestsDirectory(): string { + $suiteDirectory = []; if (is_null($this->config)) { return self::DEFAULT_TESTS_PATH; } $suiteDirectory = $this->config->xpath('/phpunit/testsuites/testsuite/directory'); - // @phpstan-ignore-next-line - if (! $suiteDirectory || count($suiteDirectory) === 0) { + if ($suiteDirectory === []) { return self::DEFAULT_TESTS_PATH; } @@ -68,7 +68,7 @@ final class ConfigLoader /** * Get the configuration file path. */ - public function getConfigurationFilePath(): string|false + public function getConfigurationFilePath(): string|bool { $candidates = [ $this->rootPath.'/phpunit.xml', @@ -92,7 +92,7 @@ final class ConfigLoader { $configPath = $this->getConfigurationFilePath(); - if ($configPath === false) { + if (is_bool($configPath)) { return; } diff --git a/src/Console/Help.php b/src/Console/Help.php index 174625c5..000fb3fe 100644 --- a/src/Console/Help.php +++ b/src/Console/Help.php @@ -27,7 +27,7 @@ final class Help /** * Creates a new Console Command instance. */ - public function __construct(private OutputInterface $output) + public function __construct(private readonly OutputInterface $output) { // .. } diff --git a/src/Console/Thanks.php b/src/Console/Thanks.php index 4e24b9ae..5f418f21 100644 --- a/src/Console/Thanks.php +++ b/src/Console/Thanks.php @@ -32,7 +32,7 @@ final class Thanks /** * Creates a new Console Command instance. */ - public function __construct(private OutputInterface $output) + public function __construct(private readonly OutputInterface $output) { // .. } diff --git a/src/Expectation.php b/src/Expectation.php index 179becf1..dd23d3f0 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -70,7 +70,7 @@ final class Expectation } /** @var array|bool $value */ - $value = json_decode($this->value, true); + $value = json_decode($this->value, true, 512); return $this->toBeJson()->and($value); } @@ -159,7 +159,7 @@ final class Expectation * @param (callable(self, self): void)|TSequenceValue ...$callbacks * @return self */ - public function sequence(mixed ...$callbacks): Expectation + public function sequence(mixed ...$callbacks): self { if (! is_iterable($this->value)) { throw new BadMethodCallException('Expectation value is not iterable.'); @@ -203,7 +203,7 @@ final class Expectation * @param array): mixed)|TValue> $expressions * @return self */ - public function match(mixed $subject, array $expressions): Expectation + public function match(mixed $subject, array $expressions): self { $subject = $subject instanceof Closure ? $subject() : $subject; @@ -245,9 +245,7 @@ final class Expectation { $condition = is_callable($condition) ? $condition - : static function () use ($condition): bool { - return $condition; - }; + : static fn (): bool => $condition; return $this->when(! $condition(), $callback); } @@ -259,13 +257,11 @@ final class Expectation * @param callable(self): mixed $callback * @return self */ - public function when(callable|bool $condition, callable $callback): Expectation + public function when(callable|bool $condition, callable $callback): self { $condition = is_callable($condition) ? $condition - : static function () use ($condition): bool { - return $condition; - }; + : static fn (): bool => $condition; if ($condition()) { $callback($this->and($this->value)); diff --git a/src/Expectations/EachExpectation.php b/src/Expectations/EachExpectation.php index 9fa53355..56cd937b 100644 --- a/src/Expectations/EachExpectation.php +++ b/src/Expectations/EachExpectation.php @@ -23,7 +23,7 @@ final class EachExpectation * * @param Expectation $original */ - public function __construct(private Expectation $original) + public function __construct(private readonly Expectation $original) { } @@ -45,7 +45,7 @@ final class EachExpectation * * @return self */ - public function not(): EachExpectation + public function not(): self { $this->opposite = true; @@ -58,7 +58,7 @@ final class EachExpectation * @param array $arguments * @return self */ - public function __call(string $name, array $arguments): EachExpectation + public function __call(string $name, array $arguments): self { foreach ($this->original->value as $item) { /* @phpstan-ignore-next-line */ @@ -75,7 +75,7 @@ final class EachExpectation * * @return self */ - public function __get(string $name): EachExpectation + public function __get(string $name): self { /* @phpstan-ignore-next-line */ return $this->$name(); diff --git a/src/Expectations/HigherOrderExpectation.php b/src/Expectations/HigherOrderExpectation.php index df2dfc2d..2008f582 100644 --- a/src/Expectations/HigherOrderExpectation.php +++ b/src/Expectations/HigherOrderExpectation.php @@ -35,7 +35,7 @@ final class HigherOrderExpectation * @param Expectation $original * @param TValue $value */ - public function __construct(private Expectation $original, mixed $value) + public function __construct(private readonly Expectation $original, mixed $value) { $this->expectation = $this->expect($value); } @@ -45,7 +45,7 @@ final class HigherOrderExpectation * * @return self */ - public function not(): HigherOrderExpectation + public function not(): self { $this->opposite = ! $this->opposite; @@ -144,7 +144,14 @@ final class HigherOrderExpectation */ private function expectationHasMethod(string $name): bool { - return method_exists($this->original, $name) || $this->original::hasMethod($name) || $this->original::hasExtend($name); + if (method_exists($this->original, $name)) { + return true; + } + if ($this->original::hasMethod($name)) { + return true; + } + + return $this->original::hasExtend($name); } /** diff --git a/src/Expectations/OppositeExpectation.php b/src/Expectations/OppositeExpectation.php index 36d89d56..beed91a8 100644 --- a/src/Expectations/OppositeExpectation.php +++ b/src/Expectations/OppositeExpectation.php @@ -23,7 +23,7 @@ final class OppositeExpectation * * @param Expectation $original */ - public function __construct(private Expectation $original) + public function __construct(private readonly Expectation $original) { } diff --git a/src/Factories/TestCaseFactory.php b/src/Factories/TestCaseFactory.php index c0df72c6..0036be01 100644 --- a/src/Factories/TestCaseFactory.php +++ b/src/Factories/TestCaseFactory.php @@ -30,7 +30,7 @@ final class TestCaseFactory * * @var array */ - private static array $annotations = [ + private const ANNOTATIONS = [ Annotations\Depends::class, Annotations\Groups::class, Annotations\CoversNothing::class, @@ -41,7 +41,7 @@ final class TestCaseFactory * * @var array> */ - private static array $attributes = [ + private const ATTRIBUTES = [ Attributes\Covers::class, ]; @@ -84,10 +84,10 @@ final class TestCaseFactory $methods = array_values(array_filter( $this->methods, - fn ($method) => count($methodsUsingOnly) === 0 || in_array($method, $methodsUsingOnly, true) + fn ($method) => $methodsUsingOnly === [] || in_array($method, $methodsUsingOnly, true) )); - if (count($methods) > 0) { + if ($methods !== []) { $this->evaluate($this->filename, $methods); } } @@ -162,8 +162,8 @@ final class TestCaseFactory $classFQN .= $className; } - $classAvailableAttributes = array_filter(self::$attributes, fn (string $attribute) => $attribute::ABOVE_CLASS); - $methodAvailableAttributes = array_filter(self::$attributes, fn (string $attribute) => ! $attribute::ABOVE_CLASS); + $classAvailableAttributes = array_filter(self::ATTRIBUTES, fn (string $attribute) => $attribute::ABOVE_CLASS); + $methodAvailableAttributes = array_filter(self::ATTRIBUTES, fn (string $attribute) => ! $attribute::ABOVE_CLASS); $classAttributes = []; @@ -178,7 +178,7 @@ final class TestCaseFactory $methodsCode = implode('', array_map( fn (TestCaseMethodFactory $methodFactory) => $methodFactory->buildForEvaluation( $classFQN, - self::$annotations, + self::ANNOTATIONS, $methodAvailableAttributes ), $methods @@ -232,7 +232,7 @@ final class TestCaseFactory $arguments = Reflection::getFunctionArguments($method->closure); - if (count($arguments) > 0) { + if ($arguments !== []) { throw new DatasetMissing($method->filename, $method->description, $arguments); } } diff --git a/src/Factories/TestCaseMethodFactory.php b/src/Factories/TestCaseMethodFactory.php index b1666227..09cf51e2 100644 --- a/src/Factories/TestCaseMethodFactory.php +++ b/src/Factories/TestCaseMethodFactory.php @@ -62,7 +62,7 @@ final class TestCaseMethodFactory public ?string $description, public ?Closure $closure, ) { - $this->closure ??= function () { + $this->closure ??= function (): void { Assert::getCount() > 0 ?: self::markTestIncomplete(); // @phpstan-ignore-line }; @@ -106,7 +106,7 @@ final class TestCaseMethodFactory */ public function receivesArguments(): bool { - return count($this->datasets) > 0 || count($this->depends) > 0; + return $this->datasets !== [] || $this->depends !== []; } /** @@ -140,7 +140,7 @@ final class TestCaseMethodFactory $attributes = (new $attribute())->__invoke($this, $attributes); } - if (count($this->datasets) > 0) { + if ($this->datasets !== []) { $dataProviderName = $methodName.'_dataset'; $annotations[] = "@dataProvider $dataProviderName"; $datasetsCode = $this->buildDatasetForEvaluation($methodName, $dataProviderName); diff --git a/src/Functions.php b/src/Functions.php index c270528a..50571727 100644 --- a/src/Functions.php +++ b/src/Functions.php @@ -19,8 +19,8 @@ if (! function_exists('expect')) { * * @template TValue * - * @param TValue $value - * @return Expectation + * @param TValue|null $value + * @return Expectation */ function expect(mixed $value = null): Expectation { diff --git a/src/Kernel.php b/src/Kernel.php index 334e7def..7210f6b6 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -24,7 +24,7 @@ final class Kernel * * @var array */ - private static array $bootstrappers = [ + private const BOOTSTRAPPERS = [ Bootstrappers\BootExceptionHandler::class, Bootstrappers\BootSubscribers::class, Bootstrappers\BootFiles::class, @@ -34,7 +34,7 @@ final class Kernel * Creates a new Kernel instance. */ public function __construct( - private Application $application + private readonly Application $application ) { // .. } @@ -44,8 +44,7 @@ final class Kernel */ public static function boot(): self { - foreach (self::$bootstrappers as $bootstrapper) { - // @phpstan-ignore-next-line + foreach (self::BOOTSTRAPPERS as $bootstrapper) { (new $bootstrapper())->__invoke(); } @@ -123,7 +122,7 @@ final class Kernel } if ($result->hasTestErroredEvents()) { - $returnCode = self::EXCEPTION_EXIT; + return self::EXCEPTION_EXIT; } return $returnCode; diff --git a/src/Laravel/Commands/PestDuskCommand.php b/src/Laravel/Commands/PestDuskCommand.php index 725de2c4..cdad1ad4 100644 --- a/src/Laravel/Commands/PestDuskCommand.php +++ b/src/Laravel/Commands/PestDuskCommand.php @@ -32,7 +32,7 @@ final class PestDuskCommand extends DuskCommand * * @return array */ - protected function binary() + protected function binary(): array { if ('phpdbg' === PHP_SAPI) { return [PHP_BINARY, '-qrr', 'vendor/pestphp/pest/bin/pest']; diff --git a/src/Laravel/Commands/PestInstallCommand.php b/src/Laravel/Commands/PestInstallCommand.php index 1f73faf3..7f833a1f 100644 --- a/src/Laravel/Commands/PestInstallCommand.php +++ b/src/Laravel/Commands/PestInstallCommand.php @@ -30,6 +30,11 @@ final class PestInstallCommand extends Command */ protected $description = 'Creates Pest resources in your current PHPUnit test suite'; + /** + * @var string + */ + private const STUBS = 'stubs/Laravel'; + /** * Execute the console command. */ @@ -40,7 +45,6 @@ final class PestInstallCommand extends Command /* @phpstan-ignore-next-line */ $pest = base_path(testDirectory('Pest.php')); - $stubs = 'stubs/Laravel'; if (File::exists($pest)) { throw new InvalidConsoleArgument(sprintf('%s already exist', $pest)); @@ -48,7 +52,7 @@ final class PestInstallCommand extends Command File::copy(implode(DIRECTORY_SEPARATOR, [ dirname(__DIR__, 3), - $stubs, + self::STUBS, 'Pest.php', ]), $pest); diff --git a/src/Laravel/Commands/PestTestCommand.php b/src/Laravel/Commands/PestTestCommand.php index efcbe698..bdf6bfd5 100644 --- a/src/Laravel/Commands/PestTestCommand.php +++ b/src/Laravel/Commands/PestTestCommand.php @@ -52,8 +52,8 @@ final class PestTestCommand extends Command /* @phpstan-ignore-next-line */ $target = base_path($relativePath); - if (! File::isDirectory(dirname($target))) { - File::makeDirectory(dirname($target), 0777, true, true); + if (! File::isDirectory(dirname((string) $target))) { + File::makeDirectory(dirname((string) $target), 0777, true, true); } if (File::exists($target) && ! (bool) $this->option('force')) { diff --git a/src/Mixins/Expectation.php b/src/Mixins/Expectation.php index 7876499d..ed589a33 100644 --- a/src/Mixins/Expectation.php +++ b/src/Mixins/Expectation.php @@ -51,9 +51,9 @@ final class Expectation * value. Used on objects, it asserts that two * variables reference the same object. * - * @return Expectation + * @return self */ - public function toBe(mixed $expected): Expectation + public function toBe(mixed $expected): self { Assert::assertSame($expected, $this->value); @@ -63,9 +63,9 @@ final class Expectation /** * Asserts that the value is empty. * - * @return Expectation + * @return self */ - public function toBeEmpty(): Expectation + public function toBeEmpty(): self { Assert::assertEmpty($this->value); @@ -75,9 +75,9 @@ final class Expectation /** * Asserts that the value is true. * - * @return Expectation + * @return self */ - public function toBeTrue(): Expectation + public function toBeTrue(): self { Assert::assertTrue($this->value); @@ -87,9 +87,9 @@ final class Expectation /** * Asserts that the value is truthy. * - * @return Expectation + * @return self */ - public function toBeTruthy(): Expectation + public function toBeTruthy(): self { Assert::assertTrue((bool) $this->value); @@ -99,9 +99,9 @@ final class Expectation /** * Asserts that the value is false. * - * @return Expectation + * @return self */ - public function toBeFalse(): Expectation + public function toBeFalse(): self { Assert::assertFalse($this->value); @@ -111,9 +111,9 @@ final class Expectation /** * Asserts that the value is falsy. * - * @return Expectation + * @return self */ - public function toBeFalsy(): Expectation + public function toBeFalsy(): self { Assert::assertFalse((bool) $this->value); @@ -123,9 +123,9 @@ final class Expectation /** * Asserts that the value is greater than $expected. * - * @return Expectation + * @return self */ - public function toBeGreaterThan(int|float $expected): Expectation + public function toBeGreaterThan(int|float $expected): self { Assert::assertGreaterThan($expected, $this->value); @@ -135,9 +135,9 @@ final class Expectation /** * Asserts that the value is greater than or equal to $expected. * - * @return Expectation + * @return self */ - public function toBeGreaterThanOrEqual(int|float $expected): Expectation + public function toBeGreaterThanOrEqual(int|float $expected): self { Assert::assertGreaterThanOrEqual($expected, $this->value); @@ -147,9 +147,9 @@ final class Expectation /** * Asserts that the value is less than or equal to $expected. * - * @return Expectation + * @return self */ - public function toBeLessThan(int|float $expected): Expectation + public function toBeLessThan(int|float $expected): self { Assert::assertLessThan($expected, $this->value); @@ -159,9 +159,9 @@ final class Expectation /** * Asserts that the value is less than $expected. * - * @return Expectation + * @return self */ - public function toBeLessThanOrEqual(int|float $expected): Expectation + public function toBeLessThanOrEqual(int|float $expected): self { Assert::assertLessThanOrEqual($expected, $this->value); @@ -171,9 +171,9 @@ final class Expectation /** * Asserts that $needle is an element of the value. * - * @return Expectation + * @return self */ - public function toContain(mixed ...$needles): Expectation + public function toContain(mixed ...$needles): self { foreach ($needles as $needle) { if (is_string($this->value)) { @@ -194,9 +194,9 @@ final class Expectation * Asserts that the value starts with $expected. * * @param non-empty-string $expected - *@return Expectation + *@return self */ - public function toStartWith(string $expected): Expectation + public function toStartWith(string $expected): self { if (! is_string($this->value)) { InvalidExpectationValue::expected('string'); @@ -211,9 +211,9 @@ final class Expectation * Asserts that the value ends with $expected. * * @param non-empty-string $expected - *@return Expectation + *@return self */ - public function toEndWith(string $expected): Expectation + public function toEndWith(string $expected): self { if (! is_string($this->value)) { InvalidExpectationValue::expected('string'); @@ -227,9 +227,9 @@ final class Expectation /** * Asserts that $number matches value's Length. * - * @return Expectation + * @return self */ - public function toHaveLength(int $number): Expectation + public function toHaveLength(int $number): self { if (is_string($this->value)) { Assert::assertEquals($number, mb_strlen($this->value)); @@ -242,11 +242,7 @@ final class Expectation } if (is_object($this->value)) { - if (method_exists($this->value, 'toArray')) { - $array = $this->value->toArray(); - } else { - $array = (array) $this->value; - } + $array = method_exists($this->value, 'toArray') ? $this->value->toArray() : (array) $this->value; Assert::assertCount($number, $array); @@ -259,9 +255,9 @@ final class Expectation /** * Asserts that $count matches the number of elements of the value. * - * @return Expectation + * @return self */ - public function toHaveCount(int $count): Expectation + public function toHaveCount(int $count): self { if (! is_countable($this->value) && ! is_iterable($this->value)) { InvalidExpectationValue::expected('string'); @@ -275,9 +271,9 @@ final class Expectation /** * Asserts that the value contains the property $name. * - * @return Expectation + * @return self */ - public function toHaveProperty(string $name, mixed $value = null): Expectation + public function toHaveProperty(string $name, mixed $value = null): self { $this->toBeObject(); @@ -296,9 +292,9 @@ final class Expectation * Asserts that the value contains the provided properties $names. * * @param iterable $names - *@return Expectation + *@return self */ - public function toHaveProperties(iterable $names): Expectation + public function toHaveProperties(iterable $names): self { foreach ($names as $name) { $this->toHaveProperty($name); @@ -310,9 +306,9 @@ final class Expectation /** * Asserts that two variables have the same value. * - * @return Expectation + * @return self */ - public function toEqual(mixed $expected): Expectation + public function toEqual(mixed $expected): self { Assert::assertEquals($expected, $this->value); @@ -328,9 +324,9 @@ final class Expectation * are objects, each object is converted to an array containing all * private, protected and public attributes. * - * @return Expectation + * @return self */ - public function toEqualCanonicalizing(mixed $expected): Expectation + public function toEqualCanonicalizing(mixed $expected): self { Assert::assertEqualsCanonicalizing($expected, $this->value); @@ -341,9 +337,9 @@ final class Expectation * Asserts that the absolute difference between the value and $expected * is lower than $delta. * - * @return Expectation + * @return self */ - public function toEqualWithDelta(mixed $expected, float $delta): Expectation + public function toEqualWithDelta(mixed $expected, float $delta): self { Assert::assertEqualsWithDelta($expected, $this->value, $delta); @@ -354,9 +350,9 @@ final class Expectation * Asserts that the value is one of the given values. * * @param iterable $values - * @return Expectation + * @return self */ - public function toBeIn(iterable $values): Expectation + public function toBeIn(iterable $values): self { Assert::assertContains($this->value, $values); @@ -366,9 +362,9 @@ final class Expectation /** * Asserts that the value is infinite. * - * @return Expectation + * @return self */ - public function toBeInfinite(): Expectation + public function toBeInfinite(): self { Assert::assertInfinite($this->value); @@ -379,9 +375,9 @@ final class Expectation * Asserts that the value is an instance of $class. * * @param class-string $class - * @return Expectation + * @return self */ - public function toBeInstanceOf(string $class): Expectation + public function toBeInstanceOf(string $class): self { Assert::assertInstanceOf($class, $this->value); @@ -391,9 +387,9 @@ final class Expectation /** * Asserts that the value is an array. * - * @return Expectation + * @return self */ - public function toBeArray(): Expectation + public function toBeArray(): self { Assert::assertIsArray($this->value); @@ -403,9 +399,9 @@ final class Expectation /** * Asserts that the value is of type bool. * - * @return Expectation + * @return self */ - public function toBeBool(): Expectation + public function toBeBool(): self { Assert::assertIsBool($this->value); @@ -415,9 +411,9 @@ final class Expectation /** * Asserts that the value is of type callable. * - * @return Expectation + * @return self */ - public function toBeCallable(): Expectation + public function toBeCallable(): self { Assert::assertIsCallable($this->value); @@ -427,9 +423,9 @@ final class Expectation /** * Asserts that the value is of type float. * - * @return Expectation + * @return self */ - public function toBeFloat(): Expectation + public function toBeFloat(): self { Assert::assertIsFloat($this->value); @@ -439,9 +435,9 @@ final class Expectation /** * Asserts that the value is of type int. * - * @return Expectation + * @return self */ - public function toBeInt(): Expectation + public function toBeInt(): self { Assert::assertIsInt($this->value); @@ -451,9 +447,9 @@ final class Expectation /** * Asserts that the value is of type iterable. * - * @return Expectation + * @return self */ - public function toBeIterable(): Expectation + public function toBeIterable(): self { Assert::assertIsIterable($this->value); @@ -463,9 +459,9 @@ final class Expectation /** * Asserts that the value is of type numeric. * - * @return Expectation + * @return self */ - public function toBeNumeric(): Expectation + public function toBeNumeric(): self { Assert::assertIsNumeric($this->value); @@ -475,9 +471,9 @@ final class Expectation /** * Asserts that the value is of type object. * - * @return Expectation + * @return self */ - public function toBeObject(): Expectation + public function toBeObject(): self { Assert::assertIsObject($this->value); @@ -487,9 +483,9 @@ final class Expectation /** * Asserts that the value is of type resource. * - * @return Expectation + * @return self */ - public function toBeResource(): Expectation + public function toBeResource(): self { Assert::assertIsResource($this->value); @@ -499,9 +495,9 @@ final class Expectation /** * Asserts that the value is of type scalar. * - * @return Expectation + * @return self */ - public function toBeScalar(): Expectation + public function toBeScalar(): self { Assert::assertIsScalar($this->value); @@ -511,9 +507,9 @@ final class Expectation /** * Asserts that the value is of type string. * - * @return Expectation + * @return self */ - public function toBeString(): Expectation + public function toBeString(): self { Assert::assertIsString($this->value); @@ -523,9 +519,9 @@ final class Expectation /** * Asserts that the value is a JSON string. * - * @return Expectation + * @return self */ - public function toBeJson(): Expectation + public function toBeJson(): self { Assert::assertIsString($this->value); @@ -538,9 +534,9 @@ final class Expectation /** * Asserts that the value is NAN. * - * @return Expectation + * @return self */ - public function toBeNan(): Expectation + public function toBeNan(): self { Assert::assertNan($this->value); @@ -550,9 +546,9 @@ final class Expectation /** * Asserts that the value is null. * - * @return Expectation + * @return self */ - public function toBeNull(): Expectation + public function toBeNull(): self { Assert::assertNull($this->value); @@ -562,9 +558,9 @@ final class Expectation /** * Asserts that the value array has the provided $key. * - * @return Expectation + * @return self */ - public function toHaveKey(string|int $key, mixed $value = null): Expectation + public function toHaveKey(string|int $key, mixed $value = null): self { if (is_object($this->value) && method_exists($this->value, 'toArray')) { $array = $this->value->toArray(); @@ -591,9 +587,9 @@ final class Expectation * Asserts that the value array has the provided $keys. * * @param array> $keys - * @return Expectation + * @return self */ - public function toHaveKeys(array $keys): Expectation + public function toHaveKeys(array $keys): self { foreach ($keys as $k => $key) { if (is_array($key)) { @@ -609,9 +605,9 @@ final class Expectation /** * Asserts that the value is a directory. * - * @return Expectation + * @return self */ - public function toBeDirectory(): Expectation + public function toBeDirectory(): self { if (! is_string($this->value)) { InvalidExpectationValue::expected('string'); @@ -625,9 +621,9 @@ final class Expectation /** * Asserts that the value is a directory and is readable. * - * @return Expectation + * @return self */ - public function toBeReadableDirectory(): Expectation + public function toBeReadableDirectory(): self { if (! is_string($this->value)) { InvalidExpectationValue::expected('string'); @@ -641,9 +637,9 @@ final class Expectation /** * Asserts that the value is a directory and is writable. * - * @return Expectation + * @return self */ - public function toBeWritableDirectory(): Expectation + public function toBeWritableDirectory(): self { if (! is_string($this->value)) { InvalidExpectationValue::expected('string'); @@ -657,9 +653,9 @@ final class Expectation /** * Asserts that the value is a file. * - * @return Expectation + * @return self */ - public function toBeFile(): Expectation + public function toBeFile(): self { if (! is_string($this->value)) { InvalidExpectationValue::expected('string'); @@ -673,9 +669,9 @@ final class Expectation /** * Asserts that the value is a file and is readable. * - * @return Expectation + * @return self */ - public function toBeReadableFile(): Expectation + public function toBeReadableFile(): self { if (! is_string($this->value)) { InvalidExpectationValue::expected('string'); @@ -689,9 +685,9 @@ final class Expectation /** * Asserts that the value is a file and is writable. * - * @return Expectation + * @return self */ - public function toBeWritableFile(): Expectation + public function toBeWritableFile(): self { if (! is_string($this->value)) { InvalidExpectationValue::expected('string'); @@ -705,9 +701,9 @@ final class Expectation * Asserts that the value array matches the given array subset. * * @param iterable $array - * @return Expectation + * @return self */ - public function toMatchArray(iterable $array): Expectation + public function toMatchArray(iterable $array): self { if (is_object($this->value) && method_exists($this->value, 'toArray')) { $valueAsArray = $this->value->toArray(); @@ -737,9 +733,9 @@ final class Expectation * of the properties of an given object. * * @param iterable $object - * @return Expectation + * @return self */ - public function toMatchObject(iterable $object): Expectation + public function toMatchObject(iterable $object): self { foreach ((array) $object as $property => $value) { if (! is_object($this->value) && ! is_string($this->value)) { @@ -767,9 +763,9 @@ final class Expectation /** * Asserts that the value matches a regular expression. * - * @return Expectation + * @return self */ - public function toMatch(string $expression): Expectation + public function toMatch(string $expression): self { if (! is_string($this->value)) { InvalidExpectationValue::expected('string'); @@ -782,9 +778,9 @@ final class Expectation /** * Asserts that the value matches a constraint. * - * @return Expectation + * @return self */ - public function toMatchConstraint(Constraint $constraint): Expectation + public function toMatchConstraint(Constraint $constraint): self { Assert::assertThat($this->value, $constraint); @@ -793,9 +789,9 @@ final class Expectation /** * @param class-string $class - * @return Expectation + * @return self */ - public function toContainOnlyInstancesOf(string $class): Expectation + public function toContainOnlyInstancesOf(string $class): self { if (! is_iterable($this->value)) { InvalidExpectationValue::expected('iterable'); @@ -810,9 +806,9 @@ final class Expectation * Asserts that executing value throws an exception. * * @param (Closure(Throwable): mixed)|string $exception - * @return Expectation + * @return self */ - public function toThrow(callable|string $exception, string $exceptionMessage = null): Expectation + public function toThrow(callable|string $exception, string $exceptionMessage = null): self { $callback = NullClosure::create(); diff --git a/src/PendingCalls/AfterEachCall.php b/src/PendingCalls/AfterEachCall.php index 084d5b6d..585fa197 100644 --- a/src/PendingCalls/AfterEachCall.php +++ b/src/PendingCalls/AfterEachCall.php @@ -19,19 +19,19 @@ final class AfterEachCall /** * The "afterEach" closure. */ - private Closure $closure; + private readonly Closure $closure; /** * The calls that should be proxied. */ - private HigherOrderMessageCollection $proxies; + private readonly HigherOrderMessageCollection $proxies; /** * Creates a new Pending Call. */ public function __construct( - private TestSuite $testSuite, - private string $filename, + private readonly TestSuite $testSuite, + private readonly string $filename, Closure $closure = null ) { $this->closure = $closure instanceof Closure ? $closure : NullClosure::create(); diff --git a/src/PendingCalls/BeforeEachCall.php b/src/PendingCalls/BeforeEachCall.php index 7a8cf589..450a0313 100644 --- a/src/PendingCalls/BeforeEachCall.php +++ b/src/PendingCalls/BeforeEachCall.php @@ -19,19 +19,19 @@ final class BeforeEachCall /** * Holds the before each closure. */ - private \Closure $closure; + private readonly \Closure $closure; /** * The calls that should be proxied. */ - private HigherOrderMessageCollection $proxies; + private readonly HigherOrderMessageCollection $proxies; /** * Creates a new Pending Call. */ public function __construct( - private TestSuite $testSuite, - private string $filename, + private readonly TestSuite $testSuite, + private readonly string $filename, Closure $closure = null ) { $this->closure = $closure instanceof Closure ? $closure : NullClosure::create(); diff --git a/src/PendingCalls/TestCall.php b/src/PendingCalls/TestCall.php index 49511443..215b4de8 100644 --- a/src/PendingCalls/TestCall.php +++ b/src/PendingCalls/TestCall.php @@ -26,18 +26,18 @@ final class TestCall /** * The Test Case Factory. */ - private TestCaseMethodFactory $testCaseMethod; + private readonly TestCaseMethodFactory $testCaseMethod; /** * If test call is descriptionLess. */ - private bool $descriptionLess; + private readonly bool $descriptionLess; /** * Creates a new Pending Call. */ public function __construct( - private TestSuite $testSuite, + private readonly TestSuite $testSuite, string $filename, string $description = null, Closure $closure = null @@ -49,7 +49,7 @@ final class TestCall /** * Asserts that the test throws the given `$exceptionClass` when called. */ - public function throws(string|int $exception, string $exceptionMessage = null, int $exceptionCode = null): TestCall + public function throws(string|int $exception, string $exceptionMessage = null, int $exceptionCode = null): self { if (is_int($exception)) { $exceptionCode = $exception; @@ -81,13 +81,11 @@ final class TestCall * * @param (callable(): bool)|bool $condition */ - public function throwsIf(callable|bool $condition, string|int $exception, string $exceptionMessage = null, int $exceptionCode = null): TestCall + public function throwsIf(callable|bool $condition, string|int $exception, string $exceptionMessage = null, int $exceptionCode = null): self { $condition = is_callable($condition) ? $condition - : static function () use ($condition): bool { - return $condition; - }; + : static fn (): bool => $condition; if ($condition()) { return $this->throws($exception, $exceptionMessage, $exceptionCode); @@ -102,7 +100,7 @@ final class TestCall * * @param array<\Closure|iterable|string> $data */ - public function with(Closure|iterable|string ...$data): TestCall + public function with(Closure|iterable|string ...$data): self { foreach ($data as $dataset) { $this->testCaseMethod->datasets[] = $dataset; @@ -114,7 +112,7 @@ final class TestCall /** * Sets the test depends. */ - public function depends(string ...$depends): TestCall + public function depends(string ...$depends): self { foreach ($depends as $depend) { $this->testCaseMethod->depends[] = $depend; @@ -126,7 +124,7 @@ final class TestCall /** * Makes the test suite only this test case. */ - public function only(): TestCall + public function only(): self { $this->testCaseMethod->only = true; @@ -136,7 +134,7 @@ final class TestCall /** * Sets the test group(s). */ - public function group(string ...$groups): TestCall + public function group(string ...$groups): self { foreach ($groups as $group) { $this->testCaseMethod->groups[] = $group; @@ -148,7 +146,7 @@ final class TestCall /** * Skips the current test. */ - public function skip(Closure|bool|string $conditionOrMessage = true, string $message = ''): TestCall + public function skip(Closure|bool|string $conditionOrMessage = true, string $message = ''): self { $condition = is_string($conditionOrMessage) ? NullClosure::create() @@ -175,7 +173,7 @@ final class TestCall /** * Sets the covered classes or methods. */ - public function covers(string ...$classesOrFunctions): TestCall + public function covers(string ...$classesOrFunctions): self { foreach ($classesOrFunctions as $classOrFunction) { $isClass = class_exists($classOrFunction); @@ -198,7 +196,7 @@ final class TestCall /** * Sets the covered classes. */ - public function coversClass(string ...$classes): TestCall + public function coversClass(string ...$classes): self { foreach ($classes as $class) { $this->testCaseMethod->covers[] = new CoversClass($class); @@ -210,7 +208,7 @@ final class TestCall /** * Sets the covered functions. */ - public function coversFunction(string ...$functions): TestCall + public function coversFunction(string ...$functions): self { foreach ($functions as $function) { $this->testCaseMethod->covers[] = new CoversFunction($function); @@ -222,7 +220,7 @@ final class TestCall /** * Sets that the current test covers nothing. */ - public function coversNothing(): TestCall + public function coversNothing(): self { $this->testCaseMethod->covers = [new CoversNothing()]; @@ -234,7 +232,7 @@ final class TestCall * and its purpose is simply to check whether the given code can * be executed without throwing exceptions. */ - public function throwsNoExceptions(): TestCall + public function throwsNoExceptions(): self { $this->testCaseMethod->proxies->add(Backtrace::file(), Backtrace::line(), 'expectNotToPerformAssertions', []); diff --git a/src/PendingCalls/UsesCall.php b/src/PendingCalls/UsesCall.php index 47a26c6c..6e267200 100644 --- a/src/PendingCalls/UsesCall.php +++ b/src/PendingCalls/UsesCall.php @@ -46,8 +46,8 @@ final class UsesCall * @param array $classAndTraits */ public function __construct( - private string $filename, - private array $classAndTraits + private readonly string $filename, + private readonly array $classAndTraits ) { $this->targets = [$filename]; } @@ -87,7 +87,7 @@ final class UsesCall /** * Sets the test group(s). */ - public function group(string ...$groups): UsesCall + public function group(string ...$groups): self { $this->groups = array_values($groups); @@ -97,7 +97,7 @@ final class UsesCall /** * Sets the global beforeAll test hook. */ - public function beforeAll(Closure $hook): UsesCall + public function beforeAll(Closure $hook): self { $this->hooks[0] = $hook; @@ -107,7 +107,7 @@ final class UsesCall /** * Sets the global beforeEach test hook. */ - public function beforeEach(Closure $hook): UsesCall + public function beforeEach(Closure $hook): self { $this->hooks[1] = $hook; @@ -117,7 +117,7 @@ final class UsesCall /** * Sets the global afterEach test hook. */ - public function afterEach(Closure $hook): UsesCall + public function afterEach(Closure $hook): self { $this->hooks[2] = $hook; @@ -127,7 +127,7 @@ final class UsesCall /** * Sets the global afterAll test hook. */ - public function afterAll(Closure $hook): UsesCall + public function afterAll(Closure $hook): self { $this->hooks[3] = $hook; diff --git a/src/Plugins/Coverage.php b/src/Plugins/Coverage.php index 2e6cdcf1..fe8f0be6 100644 --- a/src/Plugins/Coverage.php +++ b/src/Plugins/Coverage.php @@ -40,7 +40,7 @@ final class Coverage implements AddsOutput, HandlesArguments /** * Creates a new Plugin instance. */ - public function __construct(private OutputInterface $output) + public function __construct(private readonly OutputInterface $output) { // .. } @@ -52,7 +52,10 @@ final class Coverage implements AddsOutput, HandlesArguments { $arguments = [...[''], ...array_values(array_filter($originals, function ($original): bool { foreach ([self::COVERAGE_OPTION, self::MIN_OPTION] as $option) { - if ($original === sprintf('--%s', $option) || Str::startsWith($original, sprintf('--%s=', $option))) { + if ($original === sprintf('--%s', $option)) { + return true; + } + if (Str::startsWith($original, sprintf('--%s=', $option))) { return true; } } diff --git a/src/Plugins/Init.php b/src/Plugins/Init.php index 1a6ecf88..4650d117 100644 --- a/src/Plugins/Init.php +++ b/src/Plugins/Init.php @@ -32,8 +32,8 @@ final class Init implements HandlesArguments * Creates a new Plugin instance. */ public function __construct( - private TestSuite $testSuite, - private OutputInterface $output + private readonly TestSuite $testSuite, + private readonly OutputInterface $output ) { // .. } @@ -43,10 +43,12 @@ final class Init implements HandlesArguments */ public function handleArguments(array $arguments): array { - if (! array_key_exists(1, $arguments) || $arguments[1] !== self::INIT_OPTION) { + if (! array_key_exists(1, $arguments)) { + return $arguments; + } + if ($arguments[1] !== self::INIT_OPTION) { return $arguments; } - unset($arguments[1]); $this->init(); diff --git a/src/Plugins/Memory.php b/src/Plugins/Memory.php index ffc705a4..5d29960e 100644 --- a/src/Plugins/Memory.php +++ b/src/Plugins/Memory.php @@ -24,7 +24,7 @@ final class Memory implements AddsOutput, HandlesArguments * Creates a new Plugin instance. */ public function __construct( - private OutputInterface $output + private readonly OutputInterface $output ) { // .. } @@ -47,7 +47,7 @@ final class Memory implements AddsOutput, HandlesArguments if ($this->enabled) { $this->output->writeln(sprintf( ' Memory: %s MB', - round(memory_get_usage(true) / pow(1000, 2), 3) + round(memory_get_usage(true) / 1000 ** 2, 3) )); } diff --git a/src/Plugins/Version.php b/src/Plugins/Version.php index 5452237a..943909fb 100644 --- a/src/Plugins/Version.php +++ b/src/Plugins/Version.php @@ -19,7 +19,7 @@ final class Version implements HandlesArguments * Creates a new Plugin instance. */ public function __construct( - private OutputInterface $output + private readonly OutputInterface $output ) { // .. } diff --git a/src/Repositories/DatasetsRepository.php b/src/Repositories/DatasetsRepository.php index 58866d7d..f6874fc3 100644 --- a/src/Repositories/DatasetsRepository.php +++ b/src/Repositories/DatasetsRepository.php @@ -61,11 +61,11 @@ final class DatasetsRepository } /** - * @return Closure|iterable|never + * @return Closure|array|never * * @throws ShouldNotHappen */ - public static function get(string $filename, string $description): Closure|iterable + public static function get(string $filename, string $description) { $dataset = self::$withs[$filename.'>>>'.$description]; diff --git a/src/Repositories/TempRepository.php b/src/Repositories/TempRepository.php index 57e3c9a7..9ad1b601 100644 --- a/src/Repositories/TempRepository.php +++ b/src/Repositories/TempRepository.php @@ -14,7 +14,7 @@ final class TempRepository /** * Creates a new Temp Repository instance. */ - public function __construct(private string $filename) + public function __construct(private readonly string $filename) { // .. } @@ -24,10 +24,7 @@ final class TempRepository */ public function add(string $element): void { - $this->save(array_merge( - $this->all(), - [$element] - )); + $this->save([...$this->all(), ...[$element]]); } /** @@ -59,7 +56,7 @@ final class TempRepository assert(is_string($contents)); - $all = json_decode($contents, true); + $all = json_decode($contents, true, 512, JSON_THROW_ON_ERROR); return is_array($all) ? $all : []; } @@ -71,7 +68,7 @@ final class TempRepository */ private function save(array $elements): void { - $contents = json_encode($elements); + $contents = json_encode($elements, JSON_THROW_ON_ERROR); file_put_contents(self::FOLDER.'/'.$this->filename.'.json', $contents); } diff --git a/src/Repositories/TestRepository.php b/src/Repositories/TestRepository.php index 80e4b19b..dce67e78 100644 --- a/src/Repositories/TestRepository.php +++ b/src/Repositories/TestRepository.php @@ -42,9 +42,9 @@ final class TestRepository */ public function getFilenames(): array { - $testCases = array_filter($this->testCases, static fn (TestCaseFactory $testCase) => count($testCase->methodsUsingOnly()) > 0); + $testCases = array_filter($this->testCases, static fn (TestCaseFactory $testCase) => $testCase->methodsUsingOnly() !== []); - if (count($testCases) === 0) { + if ($testCases === []) { $testCases = $this->testCases; } @@ -62,9 +62,13 @@ final class TestRepository public function use(array $classOrTraits, array $groups, array $paths, array $hooks): void { foreach ($classOrTraits as $classOrTrait) { - if (! class_exists($classOrTrait) && ! trait_exists($classOrTrait)) { - throw new TestCaseClassOrTraitNotFound($classOrTrait); + if (class_exists($classOrTrait)) { + continue; } + if (trait_exists($classOrTrait)) { + continue; + } + throw new TestCaseClassOrTraitNotFound($classOrTrait); } foreach ($paths as $path) { @@ -137,7 +141,7 @@ final class TestRepository } foreach ($testCase->methods as $method) { - $method->groups = array_merge($groups, $method->groups); + $method->groups = [...$groups, ...$method->groups]; } $testCase->factoryProxies->add($testCase->filename, 0, '__addBeforeAll', [$hooks[0] ?? null]); diff --git a/src/Support/Arr.php b/src/Support/Arr.php index 337be46c..bd80ae56 100644 --- a/src/Support/Arr.php +++ b/src/Support/Arr.php @@ -72,7 +72,7 @@ final class Arr $results = []; foreach ($array as $key => $value) { - if (is_array($value) && count($value) > 0) { + if (is_array($value) && $value !== []) { $results = array_merge($results, static::dot($value, $prepend.$key.'.')); } else { $results[$prepend.$value] = $value; diff --git a/src/Support/Closure.php b/src/Support/Closure.php index decb9b71..ebc8c769 100644 --- a/src/Support/Closure.php +++ b/src/Support/Closure.php @@ -15,7 +15,6 @@ final class Closure /** * Binds the given closure to the given "this". * - * @return BaseClosure|never * * @throws ShouldNotHappen */ diff --git a/src/Support/Container.php b/src/Support/Container.php index c2314875..f5b41187 100644 --- a/src/Support/Container.php +++ b/src/Support/Container.php @@ -26,7 +26,7 @@ final class Container public static function getInstance(): self { if (static::$instance === null) { - static::$instance = new static(); + static::$instance = new self(); } return static::$instance; @@ -49,10 +49,8 @@ final class Container /** * Adds the given instance to the container. - * - * @param mixed $instance */ - public function add(string $id, $instance): void + public function add(string $id, mixed $instance): void { $this->instances[$id] = $instance; } diff --git a/src/Support/Coverage.php b/src/Support/Coverage.php index 681a4cf1..8e1fcd5a 100644 --- a/src/Support/Coverage.php +++ b/src/Support/Coverage.php @@ -153,7 +153,7 @@ final class Coverage $shouldBeNewLine = true; $eachLine = function (array $array, array $tests, int $line) use (&$shouldBeNewLine): array { - if (count($tests) > 0) { + if ($tests !== []) { $shouldBeNewLine = true; return $array; @@ -168,8 +168,8 @@ final class Coverage $lastKey = count($array) - 1; - if (array_key_exists($lastKey, $array) && str_contains($array[$lastKey], '..')) { - [$from] = explode('..', $array[$lastKey]); + if (array_key_exists($lastKey, $array) && str_contains((string) $array[$lastKey], '..')) { + [$from] = explode('..', (string) $array[$lastKey]); $array[$lastKey] = $line > $from ? sprintf('%s..%s', $from, $line) : sprintf('%s..%s', $line, $from); return $array; diff --git a/src/Support/ExpectationPipeline.php b/src/Support/ExpectationPipeline.php index e39251e0..63c5b5c1 100644 --- a/src/Support/ExpectationPipeline.php +++ b/src/Support/ExpectationPipeline.php @@ -25,17 +25,12 @@ final class ExpectationPipeline */ private array $passables; - /** - * The expectation closure. - */ - private Closure $closure; - /** * Creates a new instance of Expectation Pipeline. */ - public function __construct(Closure $closure) - { - $this->closure = $closure; + public function __construct( + private readonly Closure $closure + ) { } /** @@ -89,10 +84,6 @@ final class ExpectationPipeline */ public function carry(): Closure { - return function ($stack, $pipe): Closure { - return function () use ($stack, $pipe) { - return $pipe($stack, ...$this->passables); - }; - }; + return fn ($stack, $pipe): Closure => fn () => $pipe($stack, ...$this->passables); } } diff --git a/src/Support/HigherOrderCallables.php b/src/Support/HigherOrderCallables.php index de4fee59..3b7a74f8 100644 --- a/src/Support/HigherOrderCallables.php +++ b/src/Support/HigherOrderCallables.php @@ -15,7 +15,7 @@ final class HigherOrderCallables /** * Creates a new Higher Order Callables instances. */ - public function __construct(private object $target) + public function __construct(private readonly object $target) { // .. } @@ -44,7 +44,7 @@ final class HigherOrderCallables * @param callable|TValue $value * @return Expectation<(callable(): mixed)|TValue> */ - public function and(mixed $value) + public function and(mixed $value): Expectation { return $this->expect($value); } diff --git a/src/Support/HigherOrderMessage.php b/src/Support/HigherOrderMessage.php index 75cfe66e..bcec5b20 100644 --- a/src/Support/HigherOrderMessage.php +++ b/src/Support/HigherOrderMessage.php @@ -25,7 +25,7 @@ final class HigherOrderMessage /** * Creates a new higher order message. * - * @param array $arguments + * @param array|null $arguments */ public function __construct( public string $filename, @@ -97,7 +97,7 @@ final class HigherOrderMessage private static function getUndefinedMethodMessage(object $target, string $methodName): string { if (\PHP_MAJOR_VERSION >= 8) { - return sprintf(sprintf(self::UNDEFINED_METHOD, sprintf('%s::%s()', $target::class, $methodName))); + return sprintf(self::UNDEFINED_METHOD, sprintf('%s::%s()', $target::class, $methodName)); } return sprintf(self::UNDEFINED_METHOD, $methodName); diff --git a/src/Support/HigherOrderTapProxy.php b/src/Support/HigherOrderTapProxy.php index d11dba28..1b5f12cf 100644 --- a/src/Support/HigherOrderTapProxy.php +++ b/src/Support/HigherOrderTapProxy.php @@ -26,10 +26,8 @@ final class HigherOrderTapProxy /** * Dynamically sets properties on the target. - * - * @param mixed $value */ - public function __set(string $property, $value): void + public function __set(string $property, mixed $value): void { $this->target->{$property} = $value; // @phpstan-ignore-line } diff --git a/src/Support/Printer.php b/src/Support/Printer.php index 4d3863ce..02f74d2f 100644 --- a/src/Support/Printer.php +++ b/src/Support/Printer.php @@ -9,10 +9,10 @@ use PHPUnit\Util\Filesystem; abstract class Printer implements \PHPUnit\Util\Printer { - /** @var resource|false */ + /** @var resource|bool */ private $stream; - private bool $isPhpStream; + private readonly bool $isPhpStream; private bool $isOpen; @@ -46,12 +46,14 @@ abstract class Printer implements \PHPUnit\Util\Printer assert($this->isOpen); assert($this->stream !== false); + // @phpstan-ignore-next-line fwrite($this->stream, $buffer); } final public function flush(): void { if ($this->isOpen && $this->isPhpStream && $this->stream !== false) { + // @phpstan-ignore-next-line fclose($this->stream); $this->isOpen = false; diff --git a/src/Support/Reflection.php b/src/Support/Reflection.php index d961a401..c16b926e 100644 --- a/src/Support/Reflection.php +++ b/src/Support/Reflection.php @@ -69,9 +69,9 @@ final class Reflection { $test = TestSuite::getInstance()->test; - return $test === null - ? static::bindCallable($callable) - : Closure::fromCallable($callable)->bindTo($test)(...$test->providedData()); + return $test instanceof \PHPUnit\Framework\TestCase + ? Closure::fromCallable($callable)->bindTo($test)(...$test->providedData()) + : static::bindCallable($callable); } /** @@ -119,9 +119,8 @@ final class Reflection * @template TValue of object * * @param TValue $object - * @param mixed $value */ - public static function setPropertyValue(object $object, string $property, $value): void + public static function setPropertyValue(object $object, string $property, mixed $value): void { /** @var ReflectionClass $reflectionClass */ $reflectionClass = new ReflectionClass($object); @@ -153,8 +152,10 @@ final class Reflection public static function getParameterClassName(ReflectionParameter $parameter): ?string { $type = $parameter->getType(); - - if (! $type instanceof ReflectionNamedType || $type->isBuiltin()) { + if (! $type instanceof ReflectionNamedType) { + return null; + } + if ($type->isBuiltin()) { return null; }