2020use PhpParser \Node \Expr \MethodCall ;
2121use PhpParser \Node \Expr \Ternary ;
2222use PhpParser \Node \Expr \Yield_ ;
23- use PhpParser \Node \InterpolatedStringPart ;
2423use PhpParser \Node \Scalar \InterpolatedString ;
2524use PhpParser \Node \Scalar \String_ ;
2625use PhpParser \Node \Stmt \Declare_ ;
@@ -107,22 +106,14 @@ public function pFileWithoutNamespace(FileWithoutNamespace $fileWithoutNamespace
107106 {
108107 return $ this ->pStmts ($ fileWithoutNamespace ->stmts );
109108 }
110- /**
111- * @api magic method in parent
112- */
113- public function pInterpolatedStringPart (InterpolatedStringPart $ interpolatedStringPart ): string
114- {
115- return $ interpolatedStringPart ->value ;
116- }
117109 protected function p (Node $ node , int $ precedence = self ::MAX_PRECEDENCE , int $ lhsPrecedence = self ::MAX_PRECEDENCE , bool $ parentFormatPreserved = \false): string
118110 {
119111 // handle already AlwaysRememberedExpr
120112 // @see https://github.com/rectorphp/rector/issues/8815#issuecomment-2503453191
121- while ($ node instanceof AlwaysRememberedExpr) {
122- $ node = $ node ->getExpr ();
113+ if ($ node instanceof AlwaysRememberedExpr) {
114+ return $ this -> p ( $ node ->getExpr (), $ precedence , $ lhsPrecedence , $ parentFormatPreserved );
123115 }
124- // handle overlapped origNode is Match_
125- // and its subnodes still have AlwaysRememberedExpr
116+ // handle overlapped origNode is Match_ and its subnodes still have AlwaysRememberedExpr
126117 $ originalNode = $ node ->getAttribute (AttributeKey::ORIGINAL_NODE );
127118 if ($ originalNode instanceof Match_) {
128119 $ subNodeNames = $ node ->getSubNodeNames ();
@@ -132,12 +123,16 @@ protected function p(Node $node, int $precedence = self::MAX_PRECEDENCE, int $lh
132123 }
133124 }
134125 }
135- $ this ->wrapBinaryOp ($ node );
126+ $ this ->wrapBinaryOpWithBrackets ($ node );
136127 $ content = parent ::p ($ node , $ precedence , $ lhsPrecedence , $ parentFormatPreserved );
128+ // remove once its fixed in php-parser, https://github.com/nikic/PHP-Parser/pull/1126
137129 if ($ node instanceof CallLike) {
138130 $ this ->cleanVariadicPlaceHolderTrailingComma ($ node );
139131 }
140- return $ node ->getAttribute (AttributeKey::WRAPPED_IN_PARENTHESES ) === \true ? '( ' . $ content . ') ' : $ content ;
132+ if ($ node ->getAttribute (AttributeKey::WRAPPED_IN_PARENTHESES )) {
133+ return '( ' . $ content . ') ' ;
134+ }
135+ return $ content ;
141136 }
142137 protected function pExpr_ArrowFunction (ArrowFunction $ arrowFunction , int $ precedence , int $ lhsPrecedence ): string
143138 {
@@ -156,7 +151,7 @@ protected function pExpr_ArrowFunction(ArrowFunction $arrowFunction, int $preced
156151 $ commentText = $ key > 0 ? $ indent . $ comment ->getText () : $ comment ->getText ();
157152 $ text .= $ commentText . "\n" ;
158153 }
159- return $ this -> pPrefixOp (ArrowFunction::class, $ this -> pAttrGroups ( $ arrowFunction -> attrGroups , \true) . $ this -> pStatic ( $ arrowFunction -> static ) . ' fn ' . ( $ arrowFunction -> byRef ? ' & ' : '' ) . ' ( ' . $ this -> pMaybeMultiline ( $ arrowFunction -> params , $ this -> phpVersion -> supportsTrailingCommaInParamList ()) . ' ) ' . ( $ arrowFunction -> returnType instanceof Node ? ' : ' . $ this -> p ($ arrowFunction-> returnType ) : '' ) . ' => ' . $ text . $ indent , $ arrowFunction -> expr , $ precedence , $ lhsPrecedence );
154+ return $ text . "\n" . $ indent . parent :: pExpr_ArrowFunction ($ arrowFunction , $ precedence , $ lhsPrecedence );
160155 }
161156 /**
162157 * This allows to use both spaces and tabs vs. original space-only
@@ -347,7 +342,7 @@ private function cleanVariadicPlaceHolderTrailingComma(CallLike $callLike): void
347342 break ;
348343 }
349344 }
350- private function wrapBinaryOp (Node $ node ): void
345+ private function wrapBinaryOpWithBrackets (Node $ node ): void
351346 {
352347 if ($ this ->exprAnalyzer ->isExprWithExprPropertyWrappable ($ node )) {
353348 $ node ->expr ->setAttribute (AttributeKey::ORIGINAL_NODE , null );
0 commit comments