From b6261f28dea77459d0f6bf59a4254709b409f9c4 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 14 Dec 2024 00:36:16 +0700 Subject: [PATCH 1/2] Bump to Rector ~2.0.0 --- composer.json | 2 +- rector.php | 8 ++------ src/Core/tests/Scope/UseCaseTest.php | 10 +++++----- src/Queue/src/Attribute/RetryPolicy.php | 2 +- src/Queue/src/RetryPolicy.php | 8 ++++---- src/Queue/src/RetryPolicyInterface.php | 4 ++-- src/Storage/src/Bucket/ReadableInterface.php | 2 +- src/Storage/src/Bucket/ReadableTrait.php | 2 +- src/Storage/src/File/ReadableInterface.php | 2 +- src/Storage/src/File/ReadableTrait.php | 2 +- src/Storage/src/Storage/ReadableInterface.php | 4 ++-- src/Storage/src/Storage/ReadableTrait.php | 4 ++-- 12 files changed, 23 insertions(+), 27 deletions(-) diff --git a/composer.json b/composer.json index 3591b7c65..a8fd0735e 100644 --- a/composer.json +++ b/composer.json @@ -142,7 +142,7 @@ "phpunit/phpunit": "10.5.3", "ramsey/collection": "^1.2", "ramsey/uuid": "^4.2.3", - "rector/rector": "1.2.10", + "rector/rector": "~2.0.0", "spiral/code-style": "^2.2", "spiral/nyholm-bridge": "^1.2", "spiral/testing": "^2.8", diff --git a/rector.php b/rector.php index d2a8c3682..84446e11d 100644 --- a/rector.php +++ b/rector.php @@ -104,14 +104,10 @@ // used by Configurator __DIR__ . '/src/Scaffolder/src/Command', ], - - \Rector\PHPUnit\PHPUnit100\Rector\MethodCall\AssertIssetToAssertObjectHasPropertyRector::class => [ - // ArrayAccess usage - __DIR__ . '/src/Session/tests/SessionTest.php', - ], ]) ->withPhpSets(php81: true) - ->withPreparedSets(deadCode: true, phpunit: true) + ->withPreparedSets(deadCode: true) + ->withComposerBased(phpunit: true) ->withConfiguredRule(ClassPropertyAssignToConstructorPromotionRector::class, [ ClassPropertyAssignToConstructorPromotionRector::RENAME_PROPERTY => false, ]); diff --git a/src/Core/tests/Scope/UseCaseTest.php b/src/Core/tests/Scope/UseCaseTest.php index fcafabd7b..51ce07bc2 100644 --- a/src/Core/tests/Scope/UseCaseTest.php +++ b/src/Core/tests/Scope/UseCaseTest.php @@ -79,7 +79,7 @@ public function testScopeBindingsAsNotSingletons(bool $theSame, string $alias, m public static function provideScopeBindingsAsNotSingletons(): iterable { - yield 'array-factory' => [false, 'foo', [Factory::class, 'makeStdClass']]; + yield 'array-factory' => [false, 'foo', (new Factory())->makeStdClass(...)]; yield 'class-name' => [false, SampleClass::class, SampleClass::class]; yield 'object' => [true, stdClass::class, new stdClass()]; } @@ -107,11 +107,11 @@ public function testScopeDefinition(): void self::assertNotSame($c1, $c2); self::assertInstanceOf(stdClass::class, $obj2); self::assertNotSame($obj1, $obj2); - }, bindings: ['foo' => [Factory::class, 'makeStdClass']]); + }, bindings: ['foo' => (new Factory())->makeStdClass(...)]); // $obj2 should be garbage collected self::assertCount(1, $this->weakMap); - }, bindings: ['foo' => [Factory::class, 'makeStdClass']]); + }, bindings: ['foo' => (new Factory())->makeStdClass(...)]); // $obj1 should be garbage collected self::assertEmpty($this->weakMap); @@ -125,7 +125,7 @@ public function testScopeDefinition(): void public function testChildContainerResolvesDepsFromParent(): void { $root = new Container(); - $root->bindSingleton('bar', [Factory::class, 'makeStdClass']); + $root->bindSingleton('bar', (new Factory())->makeStdClass(...)); $root->bind(stdClass::class, new stdClass()); $root->runScoped(function (ContainerInterface $c1) use ($root) { @@ -149,7 +149,7 @@ public function testChildContainerResolvesDepsFromParent(): void "Nested container mustn't create new instance using class name as key without definition." ); }); - }, bindings: ['foo' => [Factory::class, 'makeStdClass']]); + }, bindings: ['foo' => (new Factory())->makeStdClass(...)]); } /** diff --git a/src/Queue/src/Attribute/RetryPolicy.php b/src/Queue/src/Attribute/RetryPolicy.php index 978e37f22..dcb914cf5 100644 --- a/src/Queue/src/Attribute/RetryPolicy.php +++ b/src/Queue/src/Attribute/RetryPolicy.php @@ -25,7 +25,7 @@ class RetryPolicy { /** - * @param 0|positive-int $maxAttempts + * @param int<0, max> $maxAttempts * @param positive-int $delay in seconds. */ public function __construct( diff --git a/src/Queue/src/RetryPolicy.php b/src/Queue/src/RetryPolicy.php index a05653c74..5ddb8cf22 100644 --- a/src/Queue/src/RetryPolicy.php +++ b/src/Queue/src/RetryPolicy.php @@ -11,12 +11,12 @@ final class RetryPolicy implements RetryPolicyInterface { /** - * @var positive-int|0 + * @var int<0, max> */ private readonly int $maxAttempts; /** - * @var positive-int|0 + * @var int<0, max> */ private readonly int $delay; @@ -50,7 +50,7 @@ public function __construct(int $maxAttempts, int $delay, float $multiplier = 1) } /** - * @param positive-int|0 $attempts + * @param int<0, max> $attempts * * @return positive-int */ @@ -60,7 +60,7 @@ public function getDelay(int $attempts = 0): int } /** - * @param positive-int|0 $attempts + * @param int<0, max> $attempts */ public function isRetryable(\Throwable $exception, int $attempts = 0): bool { diff --git a/src/Queue/src/RetryPolicyInterface.php b/src/Queue/src/RetryPolicyInterface.php index e45a7850f..f773268b5 100644 --- a/src/Queue/src/RetryPolicyInterface.php +++ b/src/Queue/src/RetryPolicyInterface.php @@ -7,12 +7,12 @@ interface RetryPolicyInterface { /** - * @param positive-int|0 $attempts + * @param int<0, max> $attempts */ public function isRetryable(\Throwable $exception, int $attempts = 0): bool; /** - * @param positive-int|0 $attempts + * @param int<0, max> $attempts * * @return positive-int */ diff --git a/src/Storage/src/Bucket/ReadableInterface.php b/src/Storage/src/Bucket/ReadableInterface.php index 05185d757..c27f59e7e 100644 --- a/src/Storage/src/Bucket/ReadableInterface.php +++ b/src/Storage/src/Bucket/ReadableInterface.php @@ -46,7 +46,7 @@ public function getLastModified(string $pathname): int; /** * Returns the file size in bytes. * - * @return positive-int|0 + * @return int<0, max> * @throws FileOperationException */ public function getSize(string $pathname): int; diff --git a/src/Storage/src/Bucket/ReadableTrait.php b/src/Storage/src/Bucket/ReadableTrait.php index 671ba6850..ee6364a90 100644 --- a/src/Storage/src/Bucket/ReadableTrait.php +++ b/src/Storage/src/Bucket/ReadableTrait.php @@ -63,7 +63,7 @@ public function getLastModified(string $pathname): int } /** - * @return positive-int|0 + * @return int<0, max> */ public function getSize(string $pathname): int { diff --git a/src/Storage/src/File/ReadableInterface.php b/src/Storage/src/File/ReadableInterface.php index bda3a563d..5fca69f41 100644 --- a/src/Storage/src/File/ReadableInterface.php +++ b/src/Storage/src/File/ReadableInterface.php @@ -47,7 +47,7 @@ public function getLastModified(): int; /** * {@see BucketInterface::getSize()} * - * @return positive-int|0 + * @return int<0, max> * @throws FileOperationException */ public function getSize(): int; diff --git a/src/Storage/src/File/ReadableTrait.php b/src/Storage/src/File/ReadableTrait.php index a14127a0e..11e21ccc0 100644 --- a/src/Storage/src/File/ReadableTrait.php +++ b/src/Storage/src/File/ReadableTrait.php @@ -47,7 +47,7 @@ public function getLastModified(): int } /** - * @return positive-int|0 + * @return int<0, max> */ public function getSize(): int { diff --git a/src/Storage/src/Storage/ReadableInterface.php b/src/Storage/src/Storage/ReadableInterface.php index ba53c13a1..1a37f4670 100644 --- a/src/Storage/src/Storage/ReadableInterface.php +++ b/src/Storage/src/Storage/ReadableInterface.php @@ -45,7 +45,7 @@ public function exists(string|\Stringable $id): bool; /** * {@see BucketInterface::getLastModified()} * - * @return positive-int|0 + * @return int<0, max> * @throws FileOperationException * @throws InvalidArgumentException */ @@ -54,7 +54,7 @@ public function getLastModified(string|\Stringable $id): int; /** * {@see BucketInterface::getSize()} * - * @return positive-int|0 + * @return int<0, max> * @throws FileOperationException * @throws InvalidArgumentException */ diff --git a/src/Storage/src/Storage/ReadableTrait.php b/src/Storage/src/Storage/ReadableTrait.php index a069527b8..07ef36c9e 100644 --- a/src/Storage/src/Storage/ReadableTrait.php +++ b/src/Storage/src/Storage/ReadableTrait.php @@ -40,7 +40,7 @@ public function exists(string|\Stringable $id): bool } /** - * @return positive-int|0 + * @return int<0, max> */ public function getLastModified(string|\Stringable $id): int { @@ -50,7 +50,7 @@ public function getLastModified(string|\Stringable $id): int } /** - * @return positive-int|0 + * @return int<0, max> */ public function getSize(string|\Stringable $id): int { From 38ee09a40f18f496be2d2e5da6d00ecbbfe414bf Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 14 Dec 2024 01:25:14 +0700 Subject: [PATCH 2/2] skip FirstClassCallableRector on UseCaseTest --- rector.php | 5 +++++ src/Core/tests/Scope/UseCaseTest.php | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/rector.php b/rector.php index 84446e11d..7e6d72f48 100644 --- a/rector.php +++ b/rector.php @@ -17,6 +17,7 @@ use Rector\Php70\Rector\StmtsAwareInterface\IfIssetToCoalescingRector; use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector; use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector; +use Rector\Php81\Rector\Array_\FirstClassCallableRector; use Rector\Php81\Rector\ClassMethod\NewInInitializerRector; use Rector\Php81\Rector\Property\ReadOnlyPropertyRector; @@ -104,6 +105,10 @@ // used by Configurator __DIR__ . '/src/Scaffolder/src/Command', ], + + FirstClassCallableRector::class => [ + __DIR__ . '/src/Core/tests/Scope/UseCaseTest.php', + ], ]) ->withPhpSets(php81: true) ->withPreparedSets(deadCode: true) diff --git a/src/Core/tests/Scope/UseCaseTest.php b/src/Core/tests/Scope/UseCaseTest.php index 51ce07bc2..fcafabd7b 100644 --- a/src/Core/tests/Scope/UseCaseTest.php +++ b/src/Core/tests/Scope/UseCaseTest.php @@ -79,7 +79,7 @@ public function testScopeBindingsAsNotSingletons(bool $theSame, string $alias, m public static function provideScopeBindingsAsNotSingletons(): iterable { - yield 'array-factory' => [false, 'foo', (new Factory())->makeStdClass(...)]; + yield 'array-factory' => [false, 'foo', [Factory::class, 'makeStdClass']]; yield 'class-name' => [false, SampleClass::class, SampleClass::class]; yield 'object' => [true, stdClass::class, new stdClass()]; } @@ -107,11 +107,11 @@ public function testScopeDefinition(): void self::assertNotSame($c1, $c2); self::assertInstanceOf(stdClass::class, $obj2); self::assertNotSame($obj1, $obj2); - }, bindings: ['foo' => (new Factory())->makeStdClass(...)]); + }, bindings: ['foo' => [Factory::class, 'makeStdClass']]); // $obj2 should be garbage collected self::assertCount(1, $this->weakMap); - }, bindings: ['foo' => (new Factory())->makeStdClass(...)]); + }, bindings: ['foo' => [Factory::class, 'makeStdClass']]); // $obj1 should be garbage collected self::assertEmpty($this->weakMap); @@ -125,7 +125,7 @@ public function testScopeDefinition(): void public function testChildContainerResolvesDepsFromParent(): void { $root = new Container(); - $root->bindSingleton('bar', (new Factory())->makeStdClass(...)); + $root->bindSingleton('bar', [Factory::class, 'makeStdClass']); $root->bind(stdClass::class, new stdClass()); $root->runScoped(function (ContainerInterface $c1) use ($root) { @@ -149,7 +149,7 @@ public function testChildContainerResolvesDepsFromParent(): void "Nested container mustn't create new instance using class name as key without definition." ); }); - }, bindings: ['foo' => (new Factory())->makeStdClass(...)]); + }, bindings: ['foo' => [Factory::class, 'makeStdClass']]); } /**