@@ -17,7 +17,7 @@ class Standard extends PrettyPrinterAbstract {
1717 // Special nodes
1818
1919 protected function pParam (Node \Param $ node ): string {
20- return $ this ->pAttrGroups ($ node ->attrGroups , true )
20+ return $ this ->pAttrGroups ($ node ->attrGroups , $ this -> phpVersion -> supportsAttributes () )
2121 . $ this ->pModifiers ($ node ->flags )
2222 . ($ node ->type ? $ this ->p ($ node ->type ) . ' ' : '' )
2323 . ($ node ->byRef ? '& ' : '' )
@@ -656,7 +656,7 @@ protected function pExpr_Closure(Expr\Closure $node): string {
656656 return $ this ->pAttrGroups ($ node ->attrGroups , true )
657657 . $ this ->pStatic ($ node ->static )
658658 . 'function ' . ($ node ->byRef ? '& ' : '' )
659- . '( ' . $ this ->pMaybeMultiline ($ node ->params , $ this -> phpVersion -> supportsTrailingCommaInParamList () ) . ') '
659+ . '( ' . $ this ->pParams ($ node ->params ) . ') '
660660 . (!empty ($ node ->uses ) ? ' use ( ' . $ this ->pCommaSeparated ($ node ->uses ) . ') ' : '' )
661661 . (null !== $ node ->returnType ? ': ' . $ this ->p ($ node ->returnType ) : '' )
662662 . ' { ' . $ this ->pStmts ($ node ->stmts ) . $ this ->nl . '} ' ;
@@ -688,7 +688,7 @@ protected function pExpr_ArrowFunction(Expr\ArrowFunction $node, int $precedence
688688 $ this ->pAttrGroups ($ node ->attrGroups , true )
689689 . $ this ->pStatic ($ node ->static )
690690 . 'fn ' . ($ node ->byRef ? '& ' : '' )
691- . '( ' . $ this ->pMaybeMultiline ($ node ->params , $ this -> phpVersion -> supportsTrailingCommaInParamList () ) . ') '
691+ . '( ' . $ this ->pParams ($ node ->params ) . ') '
692692 . (null !== $ node ->returnType ? ': ' . $ this ->p ($ node ->returnType ) : '' )
693693 . ' => ' ,
694694 $ node ->expr , $ precedence , $ lhsPrecedence );
@@ -845,7 +845,7 @@ protected function pPropertyHook(Node\PropertyHook $node): string {
845845 return $ this ->pAttrGroups ($ node ->attrGroups )
846846 . $ this ->pModifiers ($ node ->flags )
847847 . ($ node ->byRef ? '& ' : '' ) . $ node ->name
848- . ($ node ->params ? '( ' . $ this ->pMaybeMultiline ($ node ->params , $ this -> phpVersion -> supportsTrailingCommaInParamList () ) . ') ' : '' )
848+ . ($ node ->params ? '( ' . $ this ->pParams ($ node ->params ) . ') ' : '' )
849849 . (\is_array ($ node ->body ) ? ' { ' . $ this ->pStmts ($ node ->body ) . $ this ->nl . '} '
850850 : ($ node ->body !== null ? ' => ' . $ this ->p ($ node ->body ) : '' ) . '; ' );
851851 }
@@ -854,7 +854,7 @@ protected function pStmt_ClassMethod(Stmt\ClassMethod $node): string {
854854 return $ this ->pAttrGroups ($ node ->attrGroups )
855855 . $ this ->pModifiers ($ node ->flags )
856856 . 'function ' . ($ node ->byRef ? '& ' : '' ) . $ node ->name
857- . '( ' . $ this ->pMaybeMultiline ($ node ->params , $ this -> phpVersion -> supportsTrailingCommaInParamList () ) . ') '
857+ . '( ' . $ this ->pParams ($ node ->params ) . ') '
858858 . (null !== $ node ->returnType ? ': ' . $ this ->p ($ node ->returnType ) : '' )
859859 . (null !== $ node ->stmts
860860 ? $ this ->nl . '{ ' . $ this ->pStmts ($ node ->stmts ) . $ this ->nl . '} '
@@ -872,7 +872,7 @@ protected function pStmt_ClassConst(Stmt\ClassConst $node): string {
872872 protected function pStmt_Function (Stmt \Function_ $ node ): string {
873873 return $ this ->pAttrGroups ($ node ->attrGroups )
874874 . 'function ' . ($ node ->byRef ? '& ' : '' ) . $ node ->name
875- . '( ' . $ this ->pMaybeMultiline ($ node ->params , $ this -> phpVersion -> supportsTrailingCommaInParamList () ) . ') '
875+ . '( ' . $ this ->pParams ($ node ->params ) . ') '
876876 . (null !== $ node ->returnType ? ': ' . $ this ->p ($ node ->returnType ) : '' )
877877 . $ this ->nl . '{ ' . $ this ->pStmts ($ node ->stmts ) . $ this ->nl . '} ' ;
878878 }
@@ -1179,6 +1179,27 @@ protected function pMaybeMultiline(array $nodes, bool $trailingComma = false): s
11791179 }
11801180 }
11811181
1182+ /** @param Node\Param[] $params
1183+ */
1184+ private function hasParamWithAttributes (array $ params ): bool {
1185+ foreach ($ params as $ param ) {
1186+ if ($ param ->attrGroups ) {
1187+ return true ;
1188+ }
1189+ }
1190+ return false ;
1191+ }
1192+
1193+ /** @param Node\Param[] $params */
1194+ protected function pParams (array $ params ): string {
1195+ if ($ this ->hasNodeWithComments ($ params ) ||
1196+ ($ this ->hasParamWithAttributes ($ params ) && !$ this ->phpVersion ->supportsAttributes ())
1197+ ) {
1198+ return $ this ->pCommaSeparatedMultiline ($ params , $ this ->phpVersion ->supportsTrailingCommaInParamList ()) . $ this ->nl ;
1199+ }
1200+ return $ this ->pCommaSeparated ($ params );
1201+ }
1202+
11821203 /** @param Node\AttributeGroup[] $nodes */
11831204 protected function pAttrGroups (array $ nodes , bool $ inline = false ): string {
11841205 $ result = '' ;
0 commit comments