Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/set/php85.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
ChrArgModuloRector::class,
SleepToSerializeRector::class,
OrdSingleByteRector::class,
WakeupToUnserializeRector::class
WakeupToUnserializeRector::class,
]
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\AddReturnDocblockForCommonObjectDenominatorRector\Fixture;

use Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\AddReturnDocblockForCommonObjectDenominatorRector\Source\FirstExtension;
use Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\AddReturnDocblockForCommonObjectDenominatorRector\Source\SecondExtension;

final class SkipDeepArrayStructure
{
public function getExtensions(): array
{
return [
[
new FirstExtension(),
new SecondExtension()
],
];
}
}
24 changes: 11 additions & 13 deletions rules/Php85/Rector/Class_/WakeupToUnserializeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -86,46 +87,43 @@ 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')
);

$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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
4 changes: 2 additions & 2 deletions src/ValueObject/PhpVersionFeature.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading