|
5 | 5 | namespace Rector\Php85\Rector\Class_; |
6 | 6 |
|
7 | 7 | use PhpParser\Node; |
| 8 | +use PhpParser\Node\Arg; |
8 | 9 | use PhpParser\Node\Expr\Assign; |
9 | 10 | use PhpParser\Node\Expr\FuncCall; |
10 | 11 | use PhpParser\Node\Expr\PropertyFetch; |
@@ -86,46 +87,43 @@ public function refactor(Node $node): ?Node |
86 | 87 | if (! $classMethod instanceof ClassMethod) { |
87 | 88 | return null; |
88 | 89 | } |
89 | | - |
| 90 | + |
90 | 91 | $classMethod->name = new Identifier('__unserialize'); |
91 | 92 | $classMethod->returnType = new Identifier('void'); |
92 | | - $param = new Param( |
93 | | - var: new Variable('data'), |
94 | | - type: new Identifier('array') |
95 | | - ); |
| 93 | + |
| 94 | + $param = new Param(var: new Variable('data'), type: new Identifier('array')); |
96 | 95 |
|
97 | 96 | $classMethod->params[] = $param; |
98 | 97 |
|
99 | 98 | $classMethod->stmts = [$this->assignProperties()]; |
100 | | - |
| 99 | + |
101 | 100 | return $node; |
102 | 101 | } |
103 | 102 |
|
104 | | - protected function assignProperties(): Foreach_{ |
| 103 | + private function assignProperties(): Foreach_ |
| 104 | + { |
105 | 105 | $assign = new Assign( |
106 | 106 | new PropertyFetch(new Variable('this'), new Variable('property')), |
107 | 107 | new Variable('value') |
108 | 108 | ); |
109 | 109 |
|
110 | 110 | $if = new If_( |
111 | 111 | new FuncCall(new Name('property_exists'), [ |
112 | | - new Node\Arg(new Variable('this')), |
113 | | - new Node\Arg(new Variable('property')), |
| 112 | + new Arg(new Variable('this')), |
| 113 | + new Arg(new Variable('property')), |
114 | 114 | ]), |
115 | 115 | [ |
116 | 116 | 'stmts' => [new Expression($assign)], |
117 | 117 | ] |
118 | 118 | ); |
119 | 119 |
|
120 | | - $foreach = new Foreach_( |
| 120 | + return new Foreach_( |
121 | 121 | new Variable('data'), |
122 | 122 | new Variable('value'), |
123 | 123 | [ |
124 | 124 | 'keyVar' => new Variable('property'), |
125 | | - 'stmts' => [$if], |
| 125 | + 'stmts' => [$if], |
126 | 126 | ] |
127 | 127 | ); |
128 | | - |
129 | | - return $foreach; |
130 | 128 | } |
131 | 129 | } |
0 commit comments