@@ -37,7 +37,6 @@ import {
3737 isReferenceLikeNode ,
3838 normalizeMagicMethodName ,
3939 isSimpleCallArgument ,
40- isMinVersion ,
4140} from "./util.mjs" ;
4241
4342const {
@@ -66,12 +65,19 @@ const {
6665 isPreviousLineEmpty,
6766} = prettierUtil ;
6867
68+ /**
69+ * Determine if we should print a trailing comma based on the config & php version
70+ *
71+ * @param options {object} Prettier Options
72+ * @param requiredVersion {number}
73+ * @returns {boolean }
74+ */
6975function shouldPrintComma ( options , requiredVersion ) {
7076 if ( ! options . trailingCommaPHP ) {
7177 return false ;
7278 }
7379
74- return isMinVersion ( options . phpVersion , requiredVersion ) ;
80+ return options . phpVersion >= requiredVersion ;
7581}
7682
7783function shouldPrintHardlineForOpenBrace ( options ) {
@@ -612,9 +618,9 @@ function printArgumentsList(path, options, print, argumentsKey = "arguments") {
612618 const lastArg = getLast ( args ) ;
613619
614620 const maybeTrailingComma =
615- ( shouldPrintComma ( options , " 7.3" ) &&
621+ ( shouldPrintComma ( options , 7.3 ) &&
616622 [ "call" , "new" , "unset" , "isset" ] . includes ( node . kind ) ) ||
617- ( shouldPrintComma ( options , " 8.0" ) &&
623+ ( shouldPrintComma ( options , 8.0 ) &&
618624 [ "function" , "closure" , "method" , "arrowfunc" , "attribute" ] . includes (
619625 node . kind
620626 ) )
@@ -1186,7 +1192,7 @@ function printAttrs(path, options, print, { inline = false } = {}) {
11861192 allAttrs . push (
11871193 group ( [
11881194 indent ( attrGroup ) ,
1189- ifBreak ( shouldPrintComma ( options , " 8.0" ) ? "," : "" ) ,
1195+ ifBreak ( shouldPrintComma ( options , 8.0 ) ? "," : "" ) ,
11901196 softline ,
11911197 "]" ,
11921198 inline ? ifBreak ( softline , " " ) : "" ,
@@ -1658,11 +1664,7 @@ function printNode(path, options, print) {
16581664 join ( [ "," , line ] , path . map ( print , "items" ) ) ,
16591665 ] ) ,
16601666 node . name
1661- ? [
1662- ifBreak ( shouldPrintComma ( options , "7.2" ) ? "," : "" ) ,
1663- softline ,
1664- "}" ,
1665- ]
1667+ ? [ ifBreak ( shouldPrintComma ( options , 7.2 ) ? "," : "" ) , softline , "}" ]
16661668 : "" ,
16671669 ] ) ;
16681670 case "useitem" :
@@ -2356,9 +2358,8 @@ function printNode(path, options, print) {
23562358 case "list" :
23572359 case "array" : {
23582360 const useShortForm =
2359- ( node . kind === "array" && isMinVersion ( options . phpVersion , "5.4" ) ) ||
2360- ( node . kind === "list" &&
2361- ( node . shortForm || isMinVersion ( options . phpVersion , "7.1" ) ) ) ;
2361+ ( node . kind === "array" && options . phpVersion >= 5.4 ) ||
2362+ ( node . kind === "list" && ( node . shortForm || options . phpVersion >= 7.1 ) ) ;
23622363 const open = useShortForm ? "[" : [ node . kind , "(" ] ;
23632364 const close = useShortForm ? "]" : ")" ;
23642365
@@ -2408,7 +2409,7 @@ function printNode(path, options, print) {
24082409 indent ( [ softline , printArrayItems ( path , options , print ) ] ) ,
24092410 needsForcedTrailingComma ? "," : "" ,
24102411 ifBreak (
2411- ! needsForcedTrailingComma && shouldPrintComma ( options , " 5.0" )
2412+ ! needsForcedTrailingComma && shouldPrintComma ( options , 5.0 )
24122413 ? [
24132414 lastElem && shouldPrintHardlineBeforeTrailingComma ( lastElem )
24142415 ? hardline
@@ -2675,7 +2676,7 @@ function printNode(path, options, print) {
26752676 if ( parent . kind === "encapsedpart" ) {
26762677 const parentParent = path . grandparent ;
26772678 let closingTagIndentation = 0 ;
2678- const flexible = isMinVersion ( options . phpVersion , " 7.3" ) ;
2679+ const flexible = options . phpVersion >= 7.3 ;
26792680 let linebreak = literalline ;
26802681 if ( parentParent . type === "heredoc" ) {
26812682 linebreak = flexible ? hardline : literalline ;
@@ -2744,7 +2745,7 @@ function printNode(path, options, print) {
27442745 case "string" :
27452746 case "shell" :
27462747 case "heredoc" : {
2747- const flexible = isMinVersion ( options . phpVersion , " 7.3" ) ;
2748+ const flexible = options . phpVersion >= 7.3 ;
27482749 const linebreak = flexible ? hardline : literalline ;
27492750 return [
27502751 getEncapsedQuotes ( node ) ,
@@ -2769,7 +2770,7 @@ function printNode(path, options, print) {
27692770 case "magic" :
27702771 return node . value ;
27712772 case "nowdoc" : {
2772- const flexible = isMinVersion ( options . phpVersion , " 7.3" ) ;
2773+ const flexible = options . phpVersion >= 7.3 ;
27732774 const linebreak = flexible ? hardline : literalline ;
27742775 return [
27752776 "<<<'" ,
0 commit comments