2121use PhpParser \Node \Expr \MethodCall ;
2222use PhpParser \Node \Expr \Ternary ;
2323use PhpParser \Node \Expr \Yield_ ;
24- use PhpParser \Node \InterpolatedStringPart ;
2524use PhpParser \Node \Scalar \InterpolatedString ;
2625use PhpParser \Node \Scalar \String_ ;
2726use PhpParser \Node \Stmt \Declare_ ;
@@ -113,14 +112,6 @@ public function pFileWithoutNamespace(FileWithoutNamespace $fileWithoutNamespace
113112 return $ this ->pStmts ($ fileWithoutNamespace ->stmts );
114113 }
115114
116- /**
117- * @api magic method in parent
118- */
119- public function pInterpolatedStringPart (InterpolatedStringPart $ interpolatedStringPart ): string
120- {
121- return $ interpolatedStringPart ->value ;
122- }
123-
124115 protected function p (
125116 Node $ node ,
126117 int $ precedence = self ::MAX_PRECEDENCE ,
@@ -129,14 +120,12 @@ protected function p(
129120 ): string {
130121 // handle already AlwaysRememberedExpr
131122 // @see https://github.com/rectorphp/rector/issues/8815#issuecomment-2503453191
132- while ($ node instanceof AlwaysRememberedExpr) {
133- $ node = $ node ->getExpr ();
123+ if ($ node instanceof AlwaysRememberedExpr) {
124+ return $ this -> p ( $ node ->getExpr (), $ precedence , $ lhsPrecedence , $ parentFormatPreserved );
134125 }
135126
136- // handle overlapped origNode is Match_
137- // and its subnodes still have AlwaysRememberedExpr
127+ // handle overlapped origNode is Match_ and its subnodes still have AlwaysRememberedExpr
138128 $ originalNode = $ node ->getAttribute (AttributeKey::ORIGINAL_NODE );
139-
140129 if ($ originalNode instanceof Match_) {
141130 $ subNodeNames = $ node ->getSubNodeNames ();
142131 foreach ($ subNodeNames as $ subNodeName ) {
@@ -146,17 +135,20 @@ protected function p(
146135 }
147136 }
148137
149- $ this ->wrapBinaryOp ($ node );
138+ $ this ->wrapBinaryOpWithBrackets ($ node );
150139
151140 $ content = parent ::p ($ node , $ precedence , $ lhsPrecedence , $ parentFormatPreserved );
152141
142+ // remove once its fixed in php-parser, https://github.com/nikic/PHP-Parser/pull/1126
153143 if ($ node instanceof CallLike) {
154144 $ this ->cleanVariadicPlaceHolderTrailingComma ($ node );
155145 }
156146
157- return $ node ->getAttribute (AttributeKey::WRAPPED_IN_PARENTHESES ) === true
158- ? ('( ' . $ content . ') ' )
159- : $ content ;
147+ if ($ node ->getAttribute (AttributeKey::WRAPPED_IN_PARENTHESES )) {
148+ return '( ' . $ content . ') ' ;
149+ }
150+
151+ return $ content ;
160152 }
161153
162154 protected function pExpr_ArrowFunction (ArrowFunction $ arrowFunction , int $ precedence , int $ lhsPrecedence ): string
@@ -169,7 +161,6 @@ protected function pExpr_ArrowFunction(ArrowFunction $arrowFunction, int $preced
169161
170162 /** @var Comment[] $comments */
171163 $ comments = $ expr ->getAttribute (AttributeKey::COMMENTS ) ?? [];
172-
173164 if ($ comments === []) {
174165 return parent ::pExpr_ArrowFunction ($ arrowFunction , $ precedence , $ lhsPrecedence );
175166 }
@@ -182,23 +173,7 @@ protected function pExpr_ArrowFunction(ArrowFunction $arrowFunction, int $preced
182173 $ text .= $ commentText . "\n" ;
183174 }
184175
185- return $ this ->pPrefixOp (
186- ArrowFunction::class,
187- $ this ->pAttrGroups ($ arrowFunction ->attrGroups , true )
188- . $ this ->pStatic ($ arrowFunction ->static )
189- . 'fn ' . ($ arrowFunction ->byRef ? '& ' : '' )
190- . '( ' . $ this ->pMaybeMultiline (
191- $ arrowFunction ->params ,
192- $ this ->phpVersion ->supportsTrailingCommaInParamList ()
193- ) . ') '
194- . ($ arrowFunction ->returnType instanceof Node ? ': ' . $ this ->p ($ arrowFunction ->returnType ) : '' )
195- . ' => '
196- . $ text
197- . $ indent ,
198- $ arrowFunction ->expr ,
199- $ precedence ,
200- $ lhsPrecedence
201- );
176+ return $ text . "\n" . $ indent . parent ::pExpr_ArrowFunction ($ arrowFunction , $ precedence , $ lhsPrecedence );
202177 }
203178
204179 /**
@@ -463,7 +438,7 @@ private function cleanVariadicPlaceHolderTrailingComma(CallLike $callLike): void
463438 }
464439 }
465440
466- private function wrapBinaryOp (Node $ node ): void
441+ private function wrapBinaryOpWithBrackets (Node $ node ): void
467442 {
468443 if ($ this ->exprAnalyzer ->isExprWithExprPropertyWrappable ($ node )) {
469444 $ node ->expr ->setAttribute (AttributeKey::ORIGINAL_NODE , null );
0 commit comments