From 34b3c87978ab7f8593a8db4efba21ab65fea5e6b Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 12 Sep 2025 18:12:34 +0700 Subject: [PATCH 1/3] [TypeDeclarationDocblocks] Skip deep array structure on AddReturnDocblockForCommonObjectDenominatorRector --- .../Fixture/skip_deep_array_structure.php.inc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 rules-tests/TypeDeclarationDocblocks/Rector/ClassMethod/AddReturnDocblockForCommonObjectDenominatorRector/Fixture/skip_deep_array_structure.php.inc diff --git a/rules-tests/TypeDeclarationDocblocks/Rector/ClassMethod/AddReturnDocblockForCommonObjectDenominatorRector/Fixture/skip_deep_array_structure.php.inc b/rules-tests/TypeDeclarationDocblocks/Rector/ClassMethod/AddReturnDocblockForCommonObjectDenominatorRector/Fixture/skip_deep_array_structure.php.inc new file mode 100644 index 00000000000..e2d5356c0d7 --- /dev/null +++ b/rules-tests/TypeDeclarationDocblocks/Rector/ClassMethod/AddReturnDocblockForCommonObjectDenominatorRector/Fixture/skip_deep_array_structure.php.inc @@ -0,0 +1,19 @@ + Date: Fri, 12 Sep 2025 18:16:14 +0700 Subject: [PATCH 2/3] comment --- .../AddReturnDocblockForCommonObjectDenominatorRector.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rules/TypeDeclarationDocblocks/Rector/ClassMethod/AddReturnDocblockForCommonObjectDenominatorRector.php b/rules/TypeDeclarationDocblocks/Rector/ClassMethod/AddReturnDocblockForCommonObjectDenominatorRector.php index 5e61dccd78e..150d923c587 100644 --- a/rules/TypeDeclarationDocblocks/Rector/ClassMethod/AddReturnDocblockForCommonObjectDenominatorRector.php +++ b/rules/TypeDeclarationDocblocks/Rector/ClassMethod/AddReturnDocblockForCommonObjectDenominatorRector.php @@ -132,6 +132,13 @@ public function refactor(Node $node): ?Node return null; } + /** + * nested structure + */ + if ($valueType->isArray()->yes()) { + return null; + } + $referencedClasses = array_merge($referencedClasses, $valueType->getReferencedClasses()); } From bb5e7d69ac238ffebfeaaeda5835fe7f0b2f1f4b Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 12 Sep 2025 18:20:54 +0700 Subject: [PATCH 3/3] rectify --- config/set/php85.php | 2 +- .../Class_/WakeupToUnserializeRector.php | 24 +++++++++---------- src/ValueObject/PhpVersionFeature.php | 4 ++-- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/config/set/php85.php b/config/set/php85.php index 3bd05b90193..a118ca891b9 100644 --- a/config/set/php85.php +++ b/config/set/php85.php @@ -42,7 +42,7 @@ ChrArgModuloRector::class, SleepToSerializeRector::class, OrdSingleByteRector::class, - WakeupToUnserializeRector::class + WakeupToUnserializeRector::class, ] ); diff --git a/rules/Php85/Rector/Class_/WakeupToUnserializeRector.php b/rules/Php85/Rector/Class_/WakeupToUnserializeRector.php index 87b7dd8256b..6f3e0c2b6a0 100644 --- a/rules/Php85/Rector/Class_/WakeupToUnserializeRector.php +++ b/rules/Php85/Rector/Class_/WakeupToUnserializeRector.php @@ -5,6 +5,7 @@ namespace Rector\Php85\Rector\Class_; use PhpParser\Node; +use PhpParser\Node\Arg; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\PropertyFetch; @@ -86,22 +87,21 @@ public function refactor(Node $node): ?Node if (! $classMethod instanceof ClassMethod) { return null; } - + $classMethod->name = new Identifier('__unserialize'); $classMethod->returnType = new Identifier('void'); - $param = new Param( - var: new Variable('data'), - type: new Identifier('array') - ); + + $param = new Param(var: new Variable('data'), type: new Identifier('array')); $classMethod->params[] = $param; $classMethod->stmts = [$this->assignProperties()]; - + return $node; } - protected function assignProperties(): Foreach_{ + private function assignProperties(): Foreach_ + { $assign = new Assign( new PropertyFetch(new Variable('this'), new Variable('property')), new Variable('value') @@ -109,23 +109,21 @@ protected function assignProperties(): Foreach_{ $if = new If_( new FuncCall(new Name('property_exists'), [ - new Node\Arg(new Variable('this')), - new Node\Arg(new Variable('property')), + new Arg(new Variable('this')), + new Arg(new Variable('property')), ]), [ 'stmts' => [new Expression($assign)], ] ); - $foreach = new Foreach_( + return new Foreach_( new Variable('data'), new Variable('value'), [ 'keyVar' => new Variable('property'), - 'stmts' => [$if], + 'stmts' => [$if], ] ); - - return $foreach; } } diff --git a/src/ValueObject/PhpVersionFeature.php b/src/ValueObject/PhpVersionFeature.php index 182b8b4a3cb..6730eebcb47 100644 --- a/src/ValueObject/PhpVersionFeature.php +++ b/src/ValueObject/PhpVersionFeature.php @@ -822,13 +822,13 @@ final class PhpVersionFeature * @var int */ public const DEPRECATED_METHOD_SLEEP = PhpVersion::PHP_85; - + /** * @see https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_the_sleep_and_wakeup_magic_methods * @var int */ public const DEPRECATED_METHOD_WAKEUP = PhpVersion::PHP_85; - + /** * @see https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_passing_string_which_are_not_one_byte_long_to_ord * @var int