From 999720ecbe175354599afd7b77a94b3df00ff1bf Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 23 Sep 2025 08:54:30 +0700 Subject: [PATCH 1/3] [TypeDeclarationDocblocks] Skip default empty on DocblockVarArrayFromPropertyDefaultsRector --- .../Fixture/skip_default_empty.php.inc | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 rules-tests/TypeDeclarationDocblocks/Rector/Class_/DocblockVarArrayFromPropertyDefaultsRector/Fixture/skip_default_empty.php.inc diff --git a/rules-tests/TypeDeclarationDocblocks/Rector/Class_/DocblockVarArrayFromPropertyDefaultsRector/Fixture/skip_default_empty.php.inc b/rules-tests/TypeDeclarationDocblocks/Rector/Class_/DocblockVarArrayFromPropertyDefaultsRector/Fixture/skip_default_empty.php.inc new file mode 100644 index 00000000000..fdd457e4e51 --- /dev/null +++ b/rules-tests/TypeDeclarationDocblocks/Rector/Class_/DocblockVarArrayFromPropertyDefaultsRector/Fixture/skip_default_empty.php.inc @@ -0,0 +1,10 @@ + \ No newline at end of file From feac8ee55ebbf46236221040fb74b1c58a9f2d86 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 23 Sep 2025 08:56:37 +0700 Subject: [PATCH 2/3] Fix --- .../TypeDeclarationDocblocks/NodeDocblockTypeDecorator.php | 4 ++++ .../Class_/DocblockVarArrayFromPropertyDefaultsRector.php | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/rules/TypeDeclarationDocblocks/NodeDocblockTypeDecorator.php b/rules/TypeDeclarationDocblocks/NodeDocblockTypeDecorator.php index f9ddfc93148..24a49d8eec6 100644 --- a/rules/TypeDeclarationDocblocks/NodeDocblockTypeDecorator.php +++ b/rules/TypeDeclarationDocblocks/NodeDocblockTypeDecorator.php @@ -124,6 +124,10 @@ private function isArrayMixed(Type $type): bool return false; } + if ($type->getItemType() instanceof \PHPStan\Type\NeverType) { + return true; + } + if (! $type->getItemType() instanceof MixedType) { return false; } diff --git a/rules/TypeDeclarationDocblocks/Rector/Class_/DocblockVarArrayFromPropertyDefaultsRector.php b/rules/TypeDeclarationDocblocks/Rector/Class_/DocblockVarArrayFromPropertyDefaultsRector.php index 61a077be7cc..aecb4d1d20b 100644 --- a/rules/TypeDeclarationDocblocks/Rector/Class_/DocblockVarArrayFromPropertyDefaultsRector.php +++ b/rules/TypeDeclarationDocblocks/Rector/Class_/DocblockVarArrayFromPropertyDefaultsRector.php @@ -89,12 +89,13 @@ public function refactor(Node $node): ?Node continue; } - $this->nodeDocblockTypeDecorator->decorateGenericIterableVarType( + if ($this->nodeDocblockTypeDecorator->decorateGenericIterableVarType( $propertyDefaultType, $propertyPhpDocInfo, $property - ); - $hasChanged = true; + )) { + $hasChanged = true; + } } if (! $hasChanged) { From 75471f350a0a01190496969247c307811c779d21 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 23 Sep 2025 08:58:53 +0700 Subject: [PATCH 3/3] cs --- rules/TypeDeclarationDocblocks/NodeDocblockTypeDecorator.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rules/TypeDeclarationDocblocks/NodeDocblockTypeDecorator.php b/rules/TypeDeclarationDocblocks/NodeDocblockTypeDecorator.php index 24a49d8eec6..a74c46e0096 100644 --- a/rules/TypeDeclarationDocblocks/NodeDocblockTypeDecorator.php +++ b/rules/TypeDeclarationDocblocks/NodeDocblockTypeDecorator.php @@ -15,6 +15,7 @@ use PHPStan\Type\ArrayType; use PHPStan\Type\IntegerType; use PHPStan\Type\MixedType; +use PHPStan\Type\NeverType; use PHPStan\Type\Type; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; use Rector\Comments\NodeDocBlock\DocBlockUpdater; @@ -124,7 +125,7 @@ private function isArrayMixed(Type $type): bool return false; } - if ($type->getItemType() instanceof \PHPStan\Type\NeverType) { + if ($type->getItemType() instanceof NeverType) { return true; }