@appthreat/atom 1.8.1 → 1.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (298) hide show
  1. package/package.json +1 -1
  2. package/phpastgen.js +7 -1
  3. package/plugins/autoload.php +1 -1
  4. package/plugins/bin/atom +1 -1
  5. package/plugins/bin/atom.bat +1 -1
  6. package/plugins/composer/autoload_classmap.php +18 -18
  7. package/plugins/composer/autoload_real.php +4 -4
  8. package/plugins/composer/autoload_static.php +22 -22
  9. package/plugins/composer/installed.json +10 -12
  10. package/plugins/composer/installed.php +9 -9
  11. package/plugins/lib/io.appthreat.atom-1.8.2-classpath.jar +0 -0
  12. package/plugins/lib/{io.appthreat.atom-1.8.1.jar → io.appthreat.atom-1.8.2.jar} +0 -0
  13. package/plugins/lib/{io.appthreat.c2cpg_3-1.1.3.jar → io.appthreat.c2cpg_3-1.1.4.jar} +0 -0
  14. package/plugins/lib/{io.appthreat.dataflowengineoss_3-1.1.3.jar → io.appthreat.dataflowengineoss_3-1.1.4.jar} +0 -0
  15. package/plugins/lib/{io.appthreat.javasrc2cpg_3-1.1.3.jar → io.appthreat.javasrc2cpg_3-1.1.4.jar} +0 -0
  16. package/plugins/lib/{io.appthreat.jimple2cpg_3-1.1.3.jar → io.appthreat.jimple2cpg_3-1.1.4.jar} +0 -0
  17. package/plugins/lib/{io.appthreat.jssrc2cpg_3-1.1.3.jar → io.appthreat.jssrc2cpg_3-1.1.4.jar} +0 -0
  18. package/plugins/lib/{io.appthreat.php2atom_3-1.1.3.jar → io.appthreat.php2atom_3-1.1.4.jar} +0 -0
  19. package/plugins/lib/{io.appthreat.pysrc2cpg_3-1.1.3.jar → io.appthreat.pysrc2cpg_3-1.1.4.jar} +0 -0
  20. package/plugins/lib/{io.appthreat.semanticcpg_3-1.1.3.jar → io.appthreat.semanticcpg_3-1.1.4.jar} +0 -0
  21. package/plugins/lib/{io.appthreat.x2cpg_3-1.1.3.jar → io.appthreat.x2cpg_3-1.1.4.jar} +0 -0
  22. package/plugins/nikic/php-parser/README.md +12 -20
  23. package/plugins/nikic/php-parser/bin/php-parse +10 -11
  24. package/plugins/nikic/php-parser/composer.json +4 -6
  25. package/plugins/nikic/php-parser/lib/PhpParser/Builder/ClassConst.php +15 -17
  26. package/plugins/nikic/php-parser/lib/PhpParser/Builder/Class_.php +30 -35
  27. package/plugins/nikic/php-parser/lib/PhpParser/Builder/Declaration.php +4 -11
  28. package/plugins/nikic/php-parser/lib/PhpParser/Builder/EnumCase.php +7 -9
  29. package/plugins/nikic/php-parser/lib/PhpParser/Builder/Enum_.php +27 -26
  30. package/plugins/nikic/php-parser/lib/PhpParser/Builder/FunctionLike.php +7 -7
  31. package/plugins/nikic/php-parser/lib/PhpParser/Builder/Function_.php +7 -7
  32. package/plugins/nikic/php-parser/lib/PhpParser/Builder/Interface_.php +10 -11
  33. package/plugins/nikic/php-parser/lib/PhpParser/Builder/Method.php +15 -16
  34. package/plugins/nikic/php-parser/lib/PhpParser/Builder/Namespace_.php +5 -5
  35. package/plugins/nikic/php-parser/lib/PhpParser/Builder/Param.php +35 -16
  36. package/plugins/nikic/php-parser/lib/PhpParser/Builder/Property.php +19 -19
  37. package/plugins/nikic/php-parser/lib/PhpParser/Builder/TraitUse.php +5 -6
  38. package/plugins/nikic/php-parser/lib/PhpParser/Builder/TraitUseAdaptation.php +28 -25
  39. package/plugins/nikic/php-parser/lib/PhpParser/Builder/Trait_.php +11 -16
  40. package/plugins/nikic/php-parser/lib/PhpParser/Builder/Use_.php +8 -8
  41. package/plugins/nikic/php-parser/lib/PhpParser/Builder.php +3 -2
  42. package/plugins/nikic/php-parser/lib/PhpParser/BuilderFactory.php +69 -45
  43. package/plugins/nikic/php-parser/lib/PhpParser/BuilderHelpers.php +19 -17
  44. package/plugins/nikic/php-parser/lib/PhpParser/Comment/Doc.php +2 -1
  45. package/plugins/nikic/php-parser/lib/PhpParser/Comment.php +67 -35
  46. package/plugins/nikic/php-parser/lib/PhpParser/ConstExprEvaluationException.php +3 -3
  47. package/plugins/nikic/php-parser/lib/PhpParser/ConstExprEvaluator.php +10 -15
  48. package/plugins/nikic/php-parser/lib/PhpParser/Error.php +33 -24
  49. package/plugins/nikic/php-parser/lib/PhpParser/ErrorHandler/Collecting.php +9 -6
  50. package/plugins/nikic/php-parser/lib/PhpParser/ErrorHandler/Throwing.php +3 -2
  51. package/plugins/nikic/php-parser/lib/PhpParser/ErrorHandler.php +3 -2
  52. package/plugins/nikic/php-parser/lib/PhpParser/Internal/DiffElem.php +7 -11
  53. package/plugins/nikic/php-parser/lib/PhpParser/Internal/Differ.php +22 -36
  54. package/plugins/nikic/php-parser/lib/PhpParser/Internal/PrintableNewAnonClassNode.php +13 -20
  55. package/plugins/nikic/php-parser/lib/PhpParser/Internal/TokenStream.php +70 -55
  56. package/plugins/nikic/php-parser/lib/PhpParser/JsonDecoder.php +10 -15
  57. package/plugins/nikic/php-parser/lib/PhpParser/Lexer/Emulative.php +93 -68
  58. package/plugins/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/AttributeEmulator.php +18 -11
  59. package/plugins/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/CoaleseEqualTokenEmulator.php +47 -0
  60. package/plugins/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/EnumTokenEmulator.php +15 -10
  61. package/plugins/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/ExplicitOctalEmulator.php +11 -12
  62. package/plugins/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/FlexibleDocStringEmulator.php +76 -0
  63. package/plugins/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/FnTokenEmulator.php +23 -0
  64. package/plugins/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/KeywordEmulator.php +25 -19
  65. package/plugins/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/MatchTokenEmulator.php +10 -6
  66. package/plugins/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/NullsafeTokenEmulator.php +29 -22
  67. package/plugins/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/NumericLiteralSeparatorEmulator.php +105 -0
  68. package/plugins/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/ReadonlyFunctionTokenEmulator.php +3 -3
  69. package/plugins/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/ReadonlyTokenEmulator.php +15 -10
  70. package/plugins/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/ReverseEmulator.php +5 -6
  71. package/plugins/nikic/php-parser/lib/PhpParser/Lexer/TokenEmulator/TokenEmulator.php +5 -10
  72. package/plugins/nikic/php-parser/lib/PhpParser/Lexer.php +513 -69
  73. package/plugins/nikic/php-parser/lib/PhpParser/NameContext.php +24 -23
  74. package/plugins/nikic/php-parser/lib/PhpParser/Node/Arg.php +15 -13
  75. package/plugins/nikic/php-parser/lib/PhpParser/Node/Attribute.php +10 -9
  76. package/plugins/nikic/php-parser/lib/PhpParser/Node/AttributeGroup.php +7 -5
  77. package/plugins/nikic/php-parser/lib/PhpParser/Node/ComplexType.php +2 -1
  78. package/plugins/nikic/php-parser/lib/PhpParser/Node/Const_.php +10 -9
  79. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/ArrayDimFetch.php +11 -10
  80. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/ArrayItem.php +39 -1
  81. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Array_.php +11 -11
  82. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/ArrowFunction.php +28 -33
  83. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Assign.php +10 -9
  84. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/BitwiseAnd.php +3 -2
  85. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/BitwiseOr.php +3 -2
  86. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/BitwiseXor.php +3 -2
  87. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Coalesce.php +3 -2
  88. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Concat.php +3 -2
  89. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Div.php +3 -2
  90. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Minus.php +3 -2
  91. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Mod.php +3 -2
  92. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Mul.php +3 -2
  93. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Plus.php +3 -2
  94. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/Pow.php +3 -2
  95. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/ShiftLeft.php +3 -2
  96. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp/ShiftRight.php +3 -2
  97. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/AssignOp.php +8 -7
  98. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/AssignRef.php +10 -9
  99. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/BitwiseAnd.php +5 -4
  100. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/BitwiseOr.php +5 -4
  101. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/BitwiseXor.php +5 -4
  102. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/BooleanAnd.php +5 -4
  103. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/BooleanOr.php +5 -4
  104. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Coalesce.php +5 -4
  105. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Concat.php +5 -4
  106. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Div.php +5 -4
  107. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Equal.php +5 -4
  108. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Greater.php +5 -4
  109. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/GreaterOrEqual.php +5 -4
  110. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Identical.php +5 -4
  111. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/LogicalAnd.php +5 -4
  112. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/LogicalOr.php +5 -4
  113. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/LogicalXor.php +5 -4
  114. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Minus.php +5 -4
  115. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Mod.php +5 -4
  116. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Mul.php +5 -4
  117. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/NotEqual.php +5 -4
  118. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/NotIdentical.php +5 -4
  119. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Plus.php +5 -4
  120. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Pow.php +5 -4
  121. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/ShiftLeft.php +5 -4
  122. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/ShiftRight.php +5 -4
  123. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Smaller.php +5 -4
  124. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/SmallerOrEqual.php +5 -4
  125. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp/Spaceship.php +5 -4
  126. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BinaryOp.php +11 -8
  127. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BitwiseNot.php +8 -7
  128. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/BooleanNot.php +8 -7
  129. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/CallLike.php +7 -3
  130. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/Array_.php +3 -2
  131. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/Bool_.php +3 -2
  132. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/Double.php +6 -5
  133. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/Int_.php +3 -2
  134. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/Object_.php +3 -2
  135. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/String_.php +3 -2
  136. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Cast/Unset_.php +3 -2
  137. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Cast.php +6 -5
  138. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/ClassConstFetch.php +10 -10
  139. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Clone_.php +8 -7
  140. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Closure.php +26 -33
  141. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/ClosureUse.php +32 -1
  142. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/ConstFetch.php +8 -7
  143. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Empty_.php +8 -7
  144. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Error.php +6 -5
  145. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/ErrorSuppress.php +8 -7
  146. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Eval_.php +8 -7
  147. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Exit_.php +11 -10
  148. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/FuncCall.php +11 -10
  149. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Include_.php +14 -13
  150. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Instanceof_.php +11 -11
  151. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Isset_.php +8 -7
  152. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/List_.php +8 -12
  153. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Match_.php +7 -8
  154. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/MethodCall.php +12 -12
  155. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/New_.php +11 -10
  156. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/NullsafeMethodCall.php +12 -12
  157. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/NullsafePropertyFetch.php +10 -10
  158. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/PostDec.php +8 -7
  159. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/PostInc.php +8 -7
  160. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/PreDec.php +7 -6
  161. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/PreInc.php +8 -7
  162. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Print_.php +8 -7
  163. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/PropertyFetch.php +10 -10
  164. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/ShellExec.php +9 -9
  165. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/StaticCall.php +13 -12
  166. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/StaticPropertyFetch.php +11 -11
  167. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Ternary.php +13 -12
  168. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Throw_.php +7 -6
  169. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/UnaryMinus.php +8 -7
  170. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/UnaryPlus.php +8 -7
  171. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Variable.php +7 -6
  172. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/YieldFrom.php +8 -7
  173. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr/Yield_.php +11 -10
  174. package/plugins/nikic/php-parser/lib/PhpParser/Node/Expr.php +2 -1
  175. package/plugins/nikic/php-parser/lib/PhpParser/Node/FunctionLike.php +8 -5
  176. package/plugins/nikic/php-parser/lib/PhpParser/Node/Identifier.php +13 -13
  177. package/plugins/nikic/php-parser/lib/PhpParser/Node/IntersectionType.php +9 -6
  178. package/plugins/nikic/php-parser/lib/PhpParser/Node/MatchArm.php +9 -8
  179. package/plugins/nikic/php-parser/lib/PhpParser/Node/Name/FullyQualified.php +9 -8
  180. package/plugins/nikic/php-parser/lib/PhpParser/Node/Name/Relative.php +9 -8
  181. package/plugins/nikic/php-parser/lib/PhpParser/Node/Name.php +56 -71
  182. package/plugins/nikic/php-parser/lib/PhpParser/Node/NullableType.php +10 -11
  183. package/plugins/nikic/php-parser/lib/PhpParser/Node/Param.php +22 -46
  184. package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/DNumber.php +75 -1
  185. package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/Encapsed.php +29 -1
  186. package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/EncapsedStringPart.php +28 -1
  187. package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/LNumber.php +78 -1
  188. package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Class_.php +5 -4
  189. package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Dir.php +5 -4
  190. package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/File.php +5 -4
  191. package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Function_.php +5 -4
  192. package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Line.php +5 -4
  193. package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Method.php +5 -4
  194. package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Namespace_.php +5 -4
  195. package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst/Trait_.php +5 -4
  196. package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/MagicConst.php +5 -4
  197. package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/String_.php +26 -30
  198. package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar.php +2 -1
  199. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Break_.php +9 -8
  200. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Case_.php +11 -10
  201. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Catch_.php +12 -11
  202. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/ClassConst.php +32 -24
  203. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/ClassLike.php +13 -13
  204. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/ClassMethod.php +54 -47
  205. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Class_.php +89 -46
  206. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Const_.php +8 -7
  207. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Continue_.php +9 -8
  208. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/DeclareDeclare.php +32 -1
  209. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Declare_.php +12 -12
  210. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Do_.php +10 -9
  211. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Echo_.php +8 -7
  212. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/ElseIf_.php +10 -9
  213. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Else_.php +8 -7
  214. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/EnumCase.php +12 -11
  215. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Enum_.php +13 -17
  216. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Expression.php +8 -7
  217. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Finally_.php +8 -7
  218. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/For_.php +15 -19
  219. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Foreach_.php +17 -20
  220. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Function_.php +24 -28
  221. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Global_.php +8 -7
  222. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Goto_.php +8 -7
  223. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/GroupUse.php +14 -16
  224. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/HaltCompiler.php +8 -7
  225. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/If_.php +15 -18
  226. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/InlineHTML.php +8 -7
  227. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Interface_.php +10 -13
  228. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Label.php +8 -7
  229. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Namespace_.php +12 -11
  230. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Nop.php +5 -4
  231. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Property.php +37 -28
  232. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/PropertyProperty.php +32 -1
  233. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Return_.php +9 -8
  234. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/StaticVar.php +35 -1
  235. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Static_.php +8 -8
  236. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Switch_.php +10 -9
  237. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Throw_.php +30 -0
  238. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/TraitUse.php +9 -8
  239. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/TraitUseAdaptation/Alias.php +13 -12
  240. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/TraitUseAdaptation/Precedence.php +10 -9
  241. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/TraitUseAdaptation.php +4 -3
  242. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Trait_.php +8 -10
  243. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/TryCatch.php +12 -11
  244. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Unset_.php +8 -7
  245. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/UseUse.php +50 -1
  246. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Use_.php +16 -16
  247. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/While_.php +10 -9
  248. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt.php +2 -1
  249. package/plugins/nikic/php-parser/lib/PhpParser/Node/UnionType.php +8 -7
  250. package/plugins/nikic/php-parser/lib/PhpParser/Node/VarLikeIdentifier.php +3 -2
  251. package/plugins/nikic/php-parser/lib/PhpParser/Node/VariadicPlaceholder.php +2 -2
  252. package/plugins/nikic/php-parser/lib/PhpParser/Node.php +29 -24
  253. package/plugins/nikic/php-parser/lib/PhpParser/NodeAbstract.php +20 -20
  254. package/plugins/nikic/php-parser/lib/PhpParser/NodeDumper.php +84 -168
  255. package/plugins/nikic/php-parser/lib/PhpParser/NodeFinder.php +19 -28
  256. package/plugins/nikic/php-parser/lib/PhpParser/NodeTraverser.php +84 -71
  257. package/plugins/nikic/php-parser/lib/PhpParser/NodeTraverserInterface.php +7 -4
  258. package/plugins/nikic/php-parser/lib/PhpParser/NodeVisitor/CloningVisitor.php +2 -1
  259. package/plugins/nikic/php-parser/lib/PhpParser/NodeVisitor/FindingVisitor.php +5 -4
  260. package/plugins/nikic/php-parser/lib/PhpParser/NodeVisitor/FirstFindingVisitor.php +7 -6
  261. package/plugins/nikic/php-parser/lib/PhpParser/NodeVisitor/NameResolver.php +28 -30
  262. package/plugins/nikic/php-parser/lib/PhpParser/NodeVisitor/NodeConnectingVisitor.php +3 -2
  263. package/plugins/nikic/php-parser/lib/PhpParser/NodeVisitor/ParentConnectingVisitor.php +11 -8
  264. package/plugins/nikic/php-parser/lib/PhpParser/NodeVisitor.php +7 -59
  265. package/plugins/nikic/php-parser/lib/PhpParser/NodeVisitorAbstract.php +2 -1
  266. package/plugins/nikic/php-parser/lib/PhpParser/Parser/Multiple.php +55 -0
  267. package/plugins/nikic/php-parser/lib/PhpParser/Parser/Php5.php +2682 -0
  268. package/plugins/nikic/php-parser/lib/PhpParser/Parser/Php7.php +1522 -1323
  269. package/plugins/nikic/php-parser/lib/PhpParser/Parser/Tokens.php +148 -0
  270. package/plugins/nikic/php-parser/lib/PhpParser/Parser.php +3 -9
  271. package/plugins/nikic/php-parser/lib/PhpParser/ParserAbstract.php +252 -433
  272. package/plugins/nikic/php-parser/lib/PhpParser/ParserFactory.php +49 -15
  273. package/plugins/nikic/php-parser/lib/PhpParser/PrettyPrinter/Standard.php +335 -386
  274. package/plugins/nikic/php-parser/lib/PhpParser/PrettyPrinterAbstract.php +438 -517
  275. package/plugins/lib/io.appthreat.atom-1.8.1-classpath.jar +0 -0
  276. package/plugins/nikic/php-parser/.php-cs-fixer.dist.php +0 -31
  277. package/plugins/nikic/php-parser/Makefile +0 -10
  278. package/plugins/nikic/php-parser/lib/PhpParser/Internal/TokenPolyfill.php +0 -237
  279. package/plugins/nikic/php-parser/lib/PhpParser/Modifiers.php +0 -69
  280. package/plugins/nikic/php-parser/lib/PhpParser/Node/ArrayItem.php +0 -43
  281. package/plugins/nikic/php-parser/lib/PhpParser/Node/ClosureUse.php +0 -36
  282. package/plugins/nikic/php-parser/lib/PhpParser/Node/DeclareItem.php +0 -37
  283. package/plugins/nikic/php-parser/lib/PhpParser/Node/InterpolatedStringPart.php +0 -32
  284. package/plugins/nikic/php-parser/lib/PhpParser/Node/PropertyItem.php +0 -37
  285. package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/Float_.php +0 -78
  286. package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/Int_.php +0 -82
  287. package/plugins/nikic/php-parser/lib/PhpParser/Node/Scalar/InterpolatedString.php +0 -34
  288. package/plugins/nikic/php-parser/lib/PhpParser/Node/StaticVar.php +0 -39
  289. package/plugins/nikic/php-parser/lib/PhpParser/Node/Stmt/Block.php +0 -29
  290. package/plugins/nikic/php-parser/lib/PhpParser/Node/UseItem.php +0 -55
  291. package/plugins/nikic/php-parser/lib/PhpParser/NodeVisitor/CommentAnnotatingVisitor.php +0 -82
  292. package/plugins/nikic/php-parser/lib/PhpParser/Parser/Php8.php +0 -2717
  293. package/plugins/nikic/php-parser/lib/PhpParser/PhpVersion.php +0 -164
  294. package/plugins/nikic/php-parser/lib/PhpParser/PrettyPrinter.php +0 -51
  295. package/plugins/nikic/php-parser/lib/PhpParser/Token.php +0 -18
  296. package/plugins/nikic/php-parser/lib/PhpParser/compatibility_tokens.php +0 -56
  297. package/plugins/nikic/php-parser/phpstan-baseline.neon +0 -236
  298. package/plugins/nikic/php-parser/phpstan.neon.dist +0 -8
@@ -3,200 +3,162 @@
3
3
  namespace PhpParser;
4
4
 
5
5
  use PhpParser\Internal\DiffElem;
6
- use PhpParser\Internal\Differ;
7
6
  use PhpParser\Internal\PrintableNewAnonClassNode;
8
7
  use PhpParser\Internal\TokenStream;
9
- use PhpParser\Node\AttributeGroup;
10
8
  use PhpParser\Node\Expr;
11
9
  use PhpParser\Node\Expr\AssignOp;
12
10
  use PhpParser\Node\Expr\BinaryOp;
13
11
  use PhpParser\Node\Expr\Cast;
14
- use PhpParser\Node\IntersectionType;
15
- use PhpParser\Node\MatchArm;
16
- use PhpParser\Node\Param;
17
12
  use PhpParser\Node\Scalar;
18
13
  use PhpParser\Node\Stmt;
19
- use PhpParser\Node\UnionType;
20
-
21
- abstract class PrettyPrinterAbstract implements PrettyPrinter {
22
- protected const FIXUP_PREC_LEFT = 0; // LHS operand affected by precedence
23
- protected const FIXUP_PREC_RIGHT = 1; // RHS operand affected by precedence
24
- protected const FIXUP_PREC_UNARY = 2; // Only operand affected by precedence
25
- protected const FIXUP_CALL_LHS = 3; // LHS of call
26
- protected const FIXUP_DEREF_LHS = 4; // LHS of dereferencing operation
27
- protected const FIXUP_STATIC_DEREF_LHS = 5; // LHS of static dereferencing operation
28
- protected const FIXUP_BRACED_NAME = 6; // Name operand that may require bracing
29
- protected const FIXUP_VAR_BRACED_NAME = 7; // Name operand that may require ${} bracing
30
- protected const FIXUP_ENCAPSED = 8; // Encapsed string part
31
- protected const FIXUP_NEW = 9; // New/instanceof operand
32
-
33
- protected const MAX_PRECEDENCE = 1000;
34
-
35
- /** @var array<class-string, array{int, int, int}> */
36
- protected array $precedenceMap = [
37
- // [precedence, precedenceLHS, precedenceRHS]
38
- // Where the latter two are the precedences to use for the LHS and RHS of a binary operator,
39
- // where 1 is added to one of the sides depending on associativity. This information is not
40
- // used for unary operators and set to -1.
41
- Expr\Clone_::class => [-10, 0, 1],
42
- BinaryOp\Pow::class => [ 0, 0, 1],
43
- Expr\BitwiseNot::class => [ 10, -1, -1],
44
- Expr\UnaryPlus::class => [ 10, -1, -1],
45
- Expr\UnaryMinus::class => [ 10, -1, -1],
46
- Cast\Int_::class => [ 10, -1, -1],
47
- Cast\Double::class => [ 10, -1, -1],
48
- Cast\String_::class => [ 10, -1, -1],
49
- Cast\Array_::class => [ 10, -1, -1],
50
- Cast\Object_::class => [ 10, -1, -1],
51
- Cast\Bool_::class => [ 10, -1, -1],
52
- Cast\Unset_::class => [ 10, -1, -1],
53
- Expr\ErrorSuppress::class => [ 10, -1, -1],
54
- Expr\Instanceof_::class => [ 20, -1, -1],
55
- Expr\BooleanNot::class => [ 30, -1, -1],
56
- BinaryOp\Mul::class => [ 40, 41, 40],
57
- BinaryOp\Div::class => [ 40, 41, 40],
58
- BinaryOp\Mod::class => [ 40, 41, 40],
59
- BinaryOp\Plus::class => [ 50, 51, 50],
60
- BinaryOp\Minus::class => [ 50, 51, 50],
61
- BinaryOp\Concat::class => [ 50, 51, 50],
62
- BinaryOp\ShiftLeft::class => [ 60, 61, 60],
63
- BinaryOp\ShiftRight::class => [ 60, 61, 60],
64
- BinaryOp\Smaller::class => [ 70, 70, 70],
65
- BinaryOp\SmallerOrEqual::class => [ 70, 70, 70],
66
- BinaryOp\Greater::class => [ 70, 70, 70],
67
- BinaryOp\GreaterOrEqual::class => [ 70, 70, 70],
68
- BinaryOp\Equal::class => [ 80, 80, 80],
69
- BinaryOp\NotEqual::class => [ 80, 80, 80],
70
- BinaryOp\Identical::class => [ 80, 80, 80],
71
- BinaryOp\NotIdentical::class => [ 80, 80, 80],
72
- BinaryOp\Spaceship::class => [ 80, 80, 80],
73
- BinaryOp\BitwiseAnd::class => [ 90, 91, 90],
74
- BinaryOp\BitwiseXor::class => [100, 101, 100],
75
- BinaryOp\BitwiseOr::class => [110, 111, 110],
76
- BinaryOp\BooleanAnd::class => [120, 121, 120],
77
- BinaryOp\BooleanOr::class => [130, 131, 130],
78
- BinaryOp\Coalesce::class => [140, 140, 141],
79
- Expr\Ternary::class => [150, -1, -1],
80
- Expr\Assign::class => [160, -1, -1],
81
- Expr\AssignRef::class => [160, -1, -1],
82
- AssignOp\Plus::class => [160, -1, -1],
83
- AssignOp\Minus::class => [160, -1, -1],
84
- AssignOp\Mul::class => [160, -1, -1],
85
- AssignOp\Div::class => [160, -1, -1],
86
- AssignOp\Concat::class => [160, -1, -1],
87
- AssignOp\Mod::class => [160, -1, -1],
88
- AssignOp\BitwiseAnd::class => [160, -1, -1],
89
- AssignOp\BitwiseOr::class => [160, -1, -1],
90
- AssignOp\BitwiseXor::class => [160, -1, -1],
91
- AssignOp\ShiftLeft::class => [160, -1, -1],
92
- AssignOp\ShiftRight::class => [160, -1, -1],
93
- AssignOp\Pow::class => [160, -1, -1],
94
- AssignOp\Coalesce::class => [160, -1, -1],
95
- Expr\YieldFrom::class => [170, -1, -1],
96
- Expr\Yield_::class => [175, -1, -1],
97
- Expr\Print_::class => [180, -1, -1],
98
- BinaryOp\LogicalAnd::class => [190, 191, 190],
99
- BinaryOp\LogicalXor::class => [200, 201, 200],
100
- BinaryOp\LogicalOr::class => [210, 211, 210],
101
- Expr\Include_::class => [220, -1, -1],
102
- Expr\ArrowFunction::class => [230, -1, -1],
103
- Expr\Throw_::class => [240, -1, -1],
14
+
15
+ abstract class PrettyPrinterAbstract
16
+ {
17
+ const FIXUP_PREC_LEFT = 0; // LHS operand affected by precedence
18
+ const FIXUP_PREC_RIGHT = 1; // RHS operand affected by precedence
19
+ const FIXUP_CALL_LHS = 2; // LHS of call
20
+ const FIXUP_DEREF_LHS = 3; // LHS of dereferencing operation
21
+ const FIXUP_BRACED_NAME = 4; // Name operand that may require bracing
22
+ const FIXUP_VAR_BRACED_NAME = 5; // Name operand that may require ${} bracing
23
+ const FIXUP_ENCAPSED = 6; // Encapsed string part
24
+ const FIXUP_NEW = 7; // New/instanceof operand
25
+ const FIXUP_STATIC_DEREF_LHS = 8; // LHS of static dereferencing operation
26
+
27
+ protected $precedenceMap = [
28
+ // [precedence, associativity]
29
+ // where for precedence -1 is %left, 0 is %nonassoc and 1 is %right
30
+ BinaryOp\Pow::class => [ 0, 1],
31
+ Expr\BitwiseNot::class => [ 10, 1],
32
+ Expr\PreInc::class => [ 10, 1],
33
+ Expr\PreDec::class => [ 10, 1],
34
+ Expr\PostInc::class => [ 10, -1],
35
+ Expr\PostDec::class => [ 10, -1],
36
+ Expr\UnaryPlus::class => [ 10, 1],
37
+ Expr\UnaryMinus::class => [ 10, 1],
38
+ Cast\Int_::class => [ 10, 1],
39
+ Cast\Double::class => [ 10, 1],
40
+ Cast\String_::class => [ 10, 1],
41
+ Cast\Array_::class => [ 10, 1],
42
+ Cast\Object_::class => [ 10, 1],
43
+ Cast\Bool_::class => [ 10, 1],
44
+ Cast\Unset_::class => [ 10, 1],
45
+ Expr\ErrorSuppress::class => [ 10, 1],
46
+ Expr\Instanceof_::class => [ 20, 0],
47
+ Expr\BooleanNot::class => [ 30, 1],
48
+ BinaryOp\Mul::class => [ 40, -1],
49
+ BinaryOp\Div::class => [ 40, -1],
50
+ BinaryOp\Mod::class => [ 40, -1],
51
+ BinaryOp\Plus::class => [ 50, -1],
52
+ BinaryOp\Minus::class => [ 50, -1],
53
+ BinaryOp\Concat::class => [ 50, -1],
54
+ BinaryOp\ShiftLeft::class => [ 60, -1],
55
+ BinaryOp\ShiftRight::class => [ 60, -1],
56
+ BinaryOp\Smaller::class => [ 70, 0],
57
+ BinaryOp\SmallerOrEqual::class => [ 70, 0],
58
+ BinaryOp\Greater::class => [ 70, 0],
59
+ BinaryOp\GreaterOrEqual::class => [ 70, 0],
60
+ BinaryOp\Equal::class => [ 80, 0],
61
+ BinaryOp\NotEqual::class => [ 80, 0],
62
+ BinaryOp\Identical::class => [ 80, 0],
63
+ BinaryOp\NotIdentical::class => [ 80, 0],
64
+ BinaryOp\Spaceship::class => [ 80, 0],
65
+ BinaryOp\BitwiseAnd::class => [ 90, -1],
66
+ BinaryOp\BitwiseXor::class => [100, -1],
67
+ BinaryOp\BitwiseOr::class => [110, -1],
68
+ BinaryOp\BooleanAnd::class => [120, -1],
69
+ BinaryOp\BooleanOr::class => [130, -1],
70
+ BinaryOp\Coalesce::class => [140, 1],
71
+ Expr\Ternary::class => [150, 0],
72
+ // parser uses %left for assignments, but they really behave as %right
73
+ Expr\Assign::class => [160, 1],
74
+ Expr\AssignRef::class => [160, 1],
75
+ AssignOp\Plus::class => [160, 1],
76
+ AssignOp\Minus::class => [160, 1],
77
+ AssignOp\Mul::class => [160, 1],
78
+ AssignOp\Div::class => [160, 1],
79
+ AssignOp\Concat::class => [160, 1],
80
+ AssignOp\Mod::class => [160, 1],
81
+ AssignOp\BitwiseAnd::class => [160, 1],
82
+ AssignOp\BitwiseOr::class => [160, 1],
83
+ AssignOp\BitwiseXor::class => [160, 1],
84
+ AssignOp\ShiftLeft::class => [160, 1],
85
+ AssignOp\ShiftRight::class => [160, 1],
86
+ AssignOp\Pow::class => [160, 1],
87
+ AssignOp\Coalesce::class => [160, 1],
88
+ Expr\YieldFrom::class => [165, 1],
89
+ Expr\Print_::class => [168, 1],
90
+ BinaryOp\LogicalAnd::class => [170, -1],
91
+ BinaryOp\LogicalXor::class => [180, -1],
92
+ BinaryOp\LogicalOr::class => [190, -1],
93
+ Expr\Include_::class => [200, -1],
104
94
  ];
105
95
 
106
96
  /** @var int Current indentation level. */
107
- protected int $indentLevel;
108
- /** @var string Newline style. Does not include current indentation. */
109
- protected string $newline;
97
+ protected $indentLevel;
110
98
  /** @var string Newline including current indentation. */
111
- protected string $nl;
112
- /** @var string|null Token placed at end of doc string to ensure it is followed by a newline.
113
- * Null if flexible doc strings are used. */
114
- protected ?string $docStringEndToken;
99
+ protected $nl;
100
+ /** @var string Token placed at end of doc string to ensure it is followed by a newline. */
101
+ protected $docStringEndToken;
115
102
  /** @var bool Whether semicolon namespaces can be used (i.e. no global namespace is used) */
116
- protected bool $canUseSemicolonNamespaces;
117
- /** @var bool Whether to use short array syntax if the node specifies no preference */
118
- protected bool $shortArraySyntax;
119
- /** @var PhpVersion PHP version to target */
120
- protected PhpVersion $phpVersion;
121
-
122
- /** @var TokenStream|null Original tokens for use in format-preserving pretty print */
123
- protected ?TokenStream $origTokens;
124
- /** @var Internal\Differ<Node> Differ for node lists */
125
- protected Differ $nodeListDiffer;
126
- /** @var array<string, bool> Map determining whether a certain character is a label character */
127
- protected array $labelCharMap;
103
+ protected $canUseSemicolonNamespaces;
104
+ /** @var array Pretty printer options */
105
+ protected $options;
106
+
107
+ /** @var TokenStream Original tokens for use in format-preserving pretty print */
108
+ protected $origTokens;
109
+ /** @var Internal\Differ Differ for node lists */
110
+ protected $nodeListDiffer;
111
+ /** @var bool[] Map determining whether a certain character is a label character */
112
+ protected $labelCharMap;
128
113
  /**
129
- * @var array<string, array<string, int>> Map from token classes and subnode names to FIXUP_* constants.
130
- * This is used during format-preserving prints to place additional parens/braces if necessary.
114
+ * @var int[][] Map from token classes and subnode names to FIXUP_* constants. This is used
115
+ * during format-preserving prints to place additional parens/braces if necessary.
131
116
  */
132
- protected array $fixupMap;
117
+ protected $fixupMap;
133
118
  /**
134
- * @var array<string, array{left?: int|string, right?: int|string}> Map from "{$node->getType()}->{$subNode}"
135
- * to ['left' => $l, 'right' => $r], where $l and $r specify the token type that needs to be stripped
136
- * when removing this node.
119
+ * @var int[][] Map from "{$node->getType()}->{$subNode}" to ['left' => $l, 'right' => $r],
120
+ * where $l and $r specify the token type that needs to be stripped when removing
121
+ * this node.
137
122
  */
138
- protected array $removalMap;
123
+ protected $removalMap;
139
124
  /**
140
- * @var array<string, array{int|string|null, bool, string|null, string|null}> Map from
141
- * "{$node->getType()}->{$subNode}" to [$find, $beforeToken, $extraLeft, $extraRight].
142
- * $find is an optional token after which the insertion occurs. $extraLeft/Right
143
- * are optionally added before/after the main insertions.
125
+ * @var mixed[] Map from "{$node->getType()}->{$subNode}" to [$find, $beforeToken, $extraLeft, $extraRight].
126
+ * $find is an optional token after which the insertion occurs. $extraLeft/Right
127
+ * are optionally added before/after the main insertions.
144
128
  */
145
- protected array $insertionMap;
129
+ protected $insertionMap;
146
130
  /**
147
- * @var array<string, string> Map From "{$class}->{$subNode}" to string that should be inserted
148
- * between elements of this list subnode.
131
+ * @var string[] Map From "{$node->getType()}->{$subNode}" to string that should be inserted
132
+ * between elements of this list subnode.
149
133
  */
150
- protected array $listInsertionMap;
151
-
152
- /**
153
- * @var array<string, array{int|string|null, string, string}>
154
- */
155
- protected array $emptyListInsertionMap;
156
- /** @var array<string, array{string, int}> Map from "{$class}->{$subNode}" to [$printFn, $token]
157
- * where $printFn is the function to print the modifiers and $token is the token before which
158
- * the modifiers should be reprinted. */
159
- protected array $modifierChangeMap;
134
+ protected $listInsertionMap;
135
+ protected $emptyListInsertionMap;
136
+ /** @var int[] Map from "{$node->getType()}->{$subNode}" to token before which the modifiers
137
+ * should be reprinted. */
138
+ protected $modifierChangeMap;
160
139
 
161
140
  /**
162
141
  * Creates a pretty printer instance using the given options.
163
142
  *
164
143
  * Supported options:
165
- * * PhpVersion $phpVersion: The PHP version to target (default to PHP 7.4). This option
166
- * controls compatibility of the generated code with older PHP
167
- * versions in cases where a simple stylistic choice exists (e.g.
168
- * array() vs []). It is safe to pretty-print an AST for a newer
169
- * PHP version while specifying an older target (but the result will
170
- * of course not be compatible with the older version in that case).
171
- * * string $newline: The newline style to use. Should be "\n" (default) or "\r\n".
172
- * * bool $shortArraySyntax: Whether to use [] instead of array() as the default array
173
- * syntax, if the node does not specify a format. Defaults to whether
174
- * the phpVersion support short array syntax.
144
+ * * bool $shortArraySyntax = false: Whether to use [] instead of array() as the default array
145
+ * syntax, if the node does not specify a format.
175
146
  *
176
- * @param array{
177
- * phpVersion?: PhpVersion, newline?: string, shortArraySyntax?: bool
178
- * } $options Dictionary of formatting options
147
+ * @param array $options Dictionary of formatting options
179
148
  */
180
149
  public function __construct(array $options = []) {
181
- $this->phpVersion = $options['phpVersion'] ?? PhpVersion::fromComponents(7, 4);
150
+ $this->docStringEndToken = '_DOC_STRING_END_' . mt_rand();
182
151
 
183
- $this->newline = $options['newline'] ?? "\n";
184
- if ($this->newline !== "\n" && $this->newline != "\r\n") {
185
- throw new \LogicException('Option "newline" must be one of "\n" or "\r\n"');
186
- }
187
-
188
- $this->shortArraySyntax =
189
- $options['shortArraySyntax'] ?? $this->phpVersion->supportsShortArraySyntax();
190
- $this->docStringEndToken =
191
- $this->phpVersion->supportsFlexibleHeredoc() ? null : '_DOC_STRING_END_' . mt_rand();
152
+ $defaultOptions = ['shortArraySyntax' => false];
153
+ $this->options = $options + $defaultOptions;
192
154
  }
193
155
 
194
156
  /**
195
157
  * Reset pretty printing state.
196
158
  */
197
- protected function resetState(): void {
159
+ protected function resetState() {
198
160
  $this->indentLevel = 0;
199
- $this->nl = $this->newline;
161
+ $this->nl = "\n";
200
162
  $this->origTokens = null;
201
163
  }
202
164
 
@@ -205,15 +167,15 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
205
167
  *
206
168
  * @param int $level Level in number of spaces
207
169
  */
208
- protected function setIndentLevel(int $level): void {
170
+ protected function setIndentLevel(int $level) {
209
171
  $this->indentLevel = $level;
210
- $this->nl = $this->newline . \str_repeat(' ', $level);
172
+ $this->nl = "\n" . \str_repeat(' ', $level);
211
173
  }
212
174
 
213
175
  /**
214
176
  * Increase indentation level.
215
177
  */
216
- protected function indent(): void {
178
+ protected function indent() {
217
179
  $this->indentLevel += 4;
218
180
  $this->nl .= ' ';
219
181
  }
@@ -221,10 +183,10 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
221
183
  /**
222
184
  * Decrease indentation level.
223
185
  */
224
- protected function outdent(): void {
186
+ protected function outdent() {
225
187
  assert($this->indentLevel >= 4);
226
188
  $this->indentLevel -= 4;
227
- $this->nl = $this->newline . str_repeat(' ', $this->indentLevel);
189
+ $this->nl = "\n" . str_repeat(' ', $this->indentLevel);
228
190
  }
229
191
 
230
192
  /**
@@ -234,7 +196,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
234
196
  *
235
197
  * @return string Pretty printed statements
236
198
  */
237
- public function prettyPrint(array $stmts): string {
199
+ public function prettyPrint(array $stmts) : string {
238
200
  $this->resetState();
239
201
  $this->preprocessNodes($stmts);
240
202
 
@@ -248,7 +210,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
248
210
  *
249
211
  * @return string Pretty printed node
250
212
  */
251
- public function prettyPrintExpr(Expr $node): string {
213
+ public function prettyPrintExpr(Expr $node) : string {
252
214
  $this->resetState();
253
215
  return $this->handleMagicTokens($this->p($node));
254
216
  }
@@ -260,15 +222,15 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
260
222
  *
261
223
  * @return string Pretty printed statements
262
224
  */
263
- public function prettyPrintFile(array $stmts): string {
225
+ public function prettyPrintFile(array $stmts) : string {
264
226
  if (!$stmts) {
265
- return "<?php" . $this->newline . $this->newline;
227
+ return "<?php\n\n";
266
228
  }
267
229
 
268
- $p = "<?php" . $this->newline . $this->newline . $this->prettyPrint($stmts);
230
+ $p = "<?php\n\n" . $this->prettyPrint($stmts);
269
231
 
270
232
  if ($stmts[0] instanceof Stmt\InlineHTML) {
271
- $p = preg_replace('/^<\?php\s+\?>\r?\n?/', '', $p);
233
+ $p = preg_replace('/^<\?php\s+\?>\n?/', '', $p);
272
234
  }
273
235
  if ($stmts[count($stmts) - 1] instanceof Stmt\InlineHTML) {
274
236
  $p = preg_replace('/<\?php$/', '', rtrim($p));
@@ -282,7 +244,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
282
244
  *
283
245
  * @param Node[] $nodes Array of nodes
284
246
  */
285
- protected function preprocessNodes(array $nodes): void {
247
+ protected function preprocessNodes(array $nodes) {
286
248
  /* We can use semicolon-namespaces unless there is a global namespace declaration */
287
249
  $this->canUseSemicolonNamespaces = true;
288
250
  foreach ($nodes as $node) {
@@ -294,17 +256,15 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
294
256
  }
295
257
 
296
258
  /**
297
- * Handles (and removes) doc-string-end tokens.
259
+ * Handles (and removes) no-indent and doc-string-end tokens.
260
+ *
261
+ * @param string $str
262
+ * @return string
298
263
  */
299
- protected function handleMagicTokens(string $str): string {
300
- if ($this->docStringEndToken !== null) {
301
- // Replace doc-string-end tokens with nothing or a newline
302
- $str = str_replace(
303
- $this->docStringEndToken . ';' . $this->newline,
304
- ';' . $this->newline,
305
- $str);
306
- $str = str_replace($this->docStringEndToken, $this->newline, $str);
307
- }
264
+ protected function handleMagicTokens(string $str) : string {
265
+ // Replace doc-string-end tokens with nothing or a newline
266
+ $str = str_replace($this->docStringEndToken . ";\n", ";\n", $str);
267
+ $str = str_replace($this->docStringEndToken, "\n", $str);
308
268
 
309
269
  return $str;
310
270
  }
@@ -312,12 +272,12 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
312
272
  /**
313
273
  * Pretty prints an array of nodes (statements) and indents them optionally.
314
274
  *
315
- * @param Node[] $nodes Array of nodes
316
- * @param bool $indent Whether to indent the printed nodes
275
+ * @param Node[] $nodes Array of nodes
276
+ * @param bool $indent Whether to indent the printed nodes
317
277
  *
318
278
  * @return string Pretty printed statements
319
279
  */
320
- protected function pStmts(array $nodes, bool $indent = true): string {
280
+ protected function pStmts(array $nodes, bool $indent = true) : string {
321
281
  if ($indent) {
322
282
  $this->indent();
323
283
  }
@@ -345,96 +305,84 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
345
305
  /**
346
306
  * Pretty-print an infix operation while taking precedence into account.
347
307
  *
348
- * @param string $class Node class of operator
349
- * @param Node $leftNode Left-hand side node
308
+ * @param string $class Node class of operator
309
+ * @param Node $leftNode Left-hand side node
350
310
  * @param string $operatorString String representation of the operator
351
- * @param Node $rightNode Right-hand side node
352
- * @param int $precedence Precedence of parent operator
353
- * @param int $lhsPrecedence Precedence for unary operator on LHS of binary operator
311
+ * @param Node $rightNode Right-hand side node
354
312
  *
355
313
  * @return string Pretty printed infix operation
356
314
  */
357
- protected function pInfixOp(
358
- string $class, Node $leftNode, string $operatorString, Node $rightNode,
359
- int $precedence, int $lhsPrecedence
360
- ): string {
361
- list($opPrecedence, $newPrecedenceLHS, $newPrecedenceRHS) = $this->precedenceMap[$class];
362
- $prefix = '';
363
- $suffix = '';
364
- if ($opPrecedence >= $precedence) {
365
- $prefix = '(';
366
- $suffix = ')';
367
- $lhsPrecedence = self::MAX_PRECEDENCE;
368
- }
369
- return $prefix . $this->p($leftNode, $newPrecedenceLHS, $newPrecedenceLHS)
370
- . $operatorString . $this->p($rightNode, $newPrecedenceRHS, $lhsPrecedence) . $suffix;
315
+ protected function pInfixOp(string $class, Node $leftNode, string $operatorString, Node $rightNode) : string {
316
+ list($precedence, $associativity) = $this->precedenceMap[$class];
317
+
318
+ return $this->pPrec($leftNode, $precedence, $associativity, -1)
319
+ . $operatorString
320
+ . $this->pPrec($rightNode, $precedence, $associativity, 1);
371
321
  }
372
322
 
373
323
  /**
374
324
  * Pretty-print a prefix operation while taking precedence into account.
375
325
  *
376
- * @param string $class Node class of operator
326
+ * @param string $class Node class of operator
377
327
  * @param string $operatorString String representation of the operator
378
- * @param Node $node Node
379
- * @param int $precedence Precedence of parent operator
380
- * @param int $lhsPrecedence Precedence for unary operator on LHS of binary operator
328
+ * @param Node $node Node
381
329
  *
382
330
  * @return string Pretty printed prefix operation
383
331
  */
384
- protected function pPrefixOp(string $class, string $operatorString, Node $node, int $precedence, int $lhsPrecedence): string {
385
- $opPrecedence = $this->precedenceMap[$class][0];
386
- $prefix = '';
387
- $suffix = '';
388
- if ($opPrecedence >= $lhsPrecedence) {
389
- $prefix = '(';
390
- $suffix = ')';
391
- $lhsPrecedence = self::MAX_PRECEDENCE;
392
- }
393
- $printedArg = $this->p($node, $opPrecedence, $lhsPrecedence);
394
- if (($operatorString === '+' && $printedArg[0] === '+') ||
395
- ($operatorString === '-' && $printedArg[0] === '-')
396
- ) {
397
- // Avoid printing +(+$a) as ++$a and similar.
398
- $printedArg = '(' . $printedArg . ')';
399
- }
400
- return $prefix . $operatorString . $printedArg . $suffix;
332
+ protected function pPrefixOp(string $class, string $operatorString, Node $node) : string {
333
+ list($precedence, $associativity) = $this->precedenceMap[$class];
334
+ return $operatorString . $this->pPrec($node, $precedence, $associativity, 1);
401
335
  }
402
336
 
403
337
  /**
404
338
  * Pretty-print a postfix operation while taking precedence into account.
405
339
  *
406
- * @param string $class Node class of operator
340
+ * @param string $class Node class of operator
407
341
  * @param string $operatorString String representation of the operator
408
- * @param Node $node Node
409
- * @param int $precedence Precedence of parent operator
410
- * @param int $lhsPrecedence Precedence for unary operator on LHS of binary operator
342
+ * @param Node $node Node
411
343
  *
412
344
  * @return string Pretty printed postfix operation
413
345
  */
414
- protected function pPostfixOp(string $class, Node $node, string $operatorString, int $precedence, int $lhsPrecedence): string {
415
- $opPrecedence = $this->precedenceMap[$class][0];
416
- $prefix = '';
417
- $suffix = '';
418
- if ($opPrecedence >= $precedence) {
419
- $prefix = '(';
420
- $suffix = ')';
421
- $lhsPrecedence = self::MAX_PRECEDENCE;
422
- }
423
- if ($opPrecedence < $lhsPrecedence) {
424
- $lhsPrecedence = $opPrecedence;
346
+ protected function pPostfixOp(string $class, Node $node, string $operatorString) : string {
347
+ list($precedence, $associativity) = $this->precedenceMap[$class];
348
+ return $this->pPrec($node, $precedence, $associativity, -1) . $operatorString;
349
+ }
350
+
351
+ /**
352
+ * Prints an expression node with the least amount of parentheses necessary to preserve the meaning.
353
+ *
354
+ * @param Node $node Node to pretty print
355
+ * @param int $parentPrecedence Precedence of the parent operator
356
+ * @param int $parentAssociativity Associativity of parent operator
357
+ * (-1 is left, 0 is nonassoc, 1 is right)
358
+ * @param int $childPosition Position of the node relative to the operator
359
+ * (-1 is left, 1 is right)
360
+ *
361
+ * @return string The pretty printed node
362
+ */
363
+ protected function pPrec(Node $node, int $parentPrecedence, int $parentAssociativity, int $childPosition) : string {
364
+ $class = \get_class($node);
365
+ if (isset($this->precedenceMap[$class])) {
366
+ $childPrecedence = $this->precedenceMap[$class][0];
367
+ if ($childPrecedence > $parentPrecedence
368
+ || ($parentPrecedence === $childPrecedence && $parentAssociativity !== $childPosition)
369
+ ) {
370
+ return '(' . $this->p($node) . ')';
371
+ }
425
372
  }
426
- return $prefix . $this->p($node, $opPrecedence, $lhsPrecedence) . $operatorString . $suffix;
373
+
374
+ return $this->p($node);
427
375
  }
428
376
 
429
377
  /**
430
378
  * Pretty prints an array of nodes and implodes the printed values.
431
379
  *
432
380
  * @param Node[] $nodes Array of Nodes to be printed
433
- * @param string $glue Character to implode with
381
+ * @param string $glue Character to implode with
434
382
  *
435
- * @return string Imploded pretty printed nodes> $pre
383
+ * @return string Imploded pretty printed nodes
436
384
  */
437
- protected function pImplode(array $nodes, string $glue = ''): string {
385
+ protected function pImplode(array $nodes, string $glue = '') : string {
438
386
  $pNodes = [];
439
387
  foreach ($nodes as $node) {
440
388
  if (null === $node) {
@@ -454,7 +402,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
454
402
  *
455
403
  * @return string Comma separated pretty printed nodes
456
404
  */
457
- protected function pCommaSeparated(array $nodes): string {
405
+ protected function pCommaSeparated(array $nodes) : string {
458
406
  return $this->pImplode($nodes, ', ');
459
407
  }
460
408
 
@@ -463,12 +411,12 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
463
411
  *
464
412
  * The result includes a leading newline and one level of indentation (same as pStmts).
465
413
  *
466
- * @param Node[] $nodes Array of Nodes to be printed
467
- * @param bool $trailingComma Whether to use a trailing comma
414
+ * @param Node[] $nodes Array of Nodes to be printed
415
+ * @param bool $trailingComma Whether to use a trailing comma
468
416
  *
469
417
  * @return string Comma separated pretty printed nodes in multiline style
470
418
  */
471
- protected function pCommaSeparatedMultiline(array $nodes, bool $trailingComma): string {
419
+ protected function pCommaSeparatedMultiline(array $nodes, bool $trailingComma) : string {
472
420
  $this->indent();
473
421
 
474
422
  $result = '';
@@ -500,7 +448,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
500
448
  *
501
449
  * @return string Reformatted text of comments
502
450
  */
503
- protected function pComments(array $comments): string {
451
+ protected function pComments(array $comments) : string {
504
452
  $formattedComments = [];
505
453
 
506
454
  foreach ($comments as $comment) {
@@ -521,11 +469,13 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
521
469
  * * The CloningVisitor must be run on the AST prior to modification.
522
470
  * * The original tokens must be provided, using the getTokens() method on the lexer.
523
471
  *
524
- * @param Node[] $stmts Modified AST with links to original AST
525
- * @param Node[] $origStmts Original AST with token offset information
526
- * @param Token[] $origTokens Tokens of the original code
472
+ * @param Node[] $stmts Modified AST with links to original AST
473
+ * @param Node[] $origStmts Original AST with token offset information
474
+ * @param array $origTokens Tokens of the original code
475
+ *
476
+ * @return string
527
477
  */
528
- public function printFormatPreserving(array $stmts, array $origStmts, array $origTokens): string {
478
+ public function printFormatPreserving(array $stmts, array $origStmts, array $origTokens) : string {
529
479
  $this->initializeNodeListDiffer();
530
480
  $this->initializeLabelCharMap();
531
481
  $this->initializeFixupMap();
@@ -543,18 +493,18 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
543
493
  $pos = 0;
544
494
  $result = $this->pArray($stmts, $origStmts, $pos, 0, 'File', 'stmts', null);
545
495
  if (null !== $result) {
546
- $result .= $this->origTokens->getTokenCode($pos, count($origTokens) - 1, 0);
496
+ $result .= $this->origTokens->getTokenCode($pos, count($origTokens), 0);
547
497
  } else {
548
498
  // Fallback
549
499
  // TODO Add <?php properly
550
- $result = "<?php" . $this->newline . $this->pStmts($stmts, false);
500
+ $result = "<?php\n" . $this->pStmts($stmts, false);
551
501
  }
552
502
 
553
- return $this->handleMagicTokens($result);
503
+ return ltrim($this->handleMagicTokens($result));
554
504
  }
555
505
 
556
- protected function pFallback(Node $node, int $precedence, int $lhsPrecedence): string {
557
- return $this->{'p' . $node->getType()}($node, $precedence, $lhsPrecedence);
506
+ protected function pFallback(Node $node) {
507
+ return $this->{'p' . $node->getType()}($node);
558
508
  }
559
509
 
560
510
  /**
@@ -563,25 +513,20 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
563
513
  * This method also handles formatting preservation for nodes.
564
514
  *
565
515
  * @param Node $node Node to be pretty printed
566
- * @param int $precedence Precedence of parent operator
567
- * @param int $lhsPrecedence Precedence for unary operator on LHS of binary operator
568
516
  * @param bool $parentFormatPreserved Whether parent node has preserved formatting
569
517
  *
570
518
  * @return string Pretty printed node
571
519
  */
572
- protected function p(
573
- Node $node, int $precedence = self::MAX_PRECEDENCE, int $lhsPrecedence = self::MAX_PRECEDENCE,
574
- bool $parentFormatPreserved = false
575
- ): string {
520
+ protected function p(Node $node, $parentFormatPreserved = false) : string {
576
521
  // No orig tokens means this is a normal pretty print without preservation of formatting
577
522
  if (!$this->origTokens) {
578
- return $this->{'p' . $node->getType()}($node, $precedence, $lhsPrecedence);
523
+ return $this->{'p' . $node->getType()}($node);
579
524
  }
580
525
 
581
- /** @var Node|null $origNode */
526
+ /** @var Node $origNode */
582
527
  $origNode = $node->getAttribute('origNode');
583
528
  if (null === $origNode) {
584
- return $this->pFallback($node, $precedence, $lhsPrecedence);
529
+ return $this->pFallback($node);
585
530
  }
586
531
 
587
532
  $class = \get_class($node);
@@ -594,17 +539,15 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
594
539
  $fallbackNode = $node;
595
540
  if ($node instanceof Expr\New_ && $node->class instanceof Stmt\Class_) {
596
541
  // Normalize node structure of anonymous classes
597
- assert($origNode instanceof Expr\New_);
598
542
  $node = PrintableNewAnonClassNode::fromNewNode($node);
599
543
  $origNode = PrintableNewAnonClassNode::fromNewNode($origNode);
600
- $class = PrintableNewAnonClassNode::class;
601
544
  }
602
545
 
603
546
  // InlineHTML node does not contain closing and opening PHP tags. If the parent formatting
604
547
  // is not preserved, then we need to use the fallback code to make sure the tags are
605
548
  // printed.
606
549
  if ($node instanceof Stmt\InlineHTML && !$parentFormatPreserved) {
607
- return $this->pFallback($fallbackNode, $precedence, $lhsPrecedence);
550
+ return $this->pFallback($fallbackNode);
608
551
  }
609
552
 
610
553
  $indentAdjustment = $this->indentLevel - $this->origTokens->getIndentationBefore($startPos);
@@ -629,27 +572,34 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
629
572
  if (is_array($subNode) && is_array($origSubNode)) {
630
573
  // Array subnode changed, we might be able to reconstruct it
631
574
  $listResult = $this->pArray(
632
- $subNode, $origSubNode, $pos, $indentAdjustment, $class, $subNodeName,
575
+ $subNode, $origSubNode, $pos, $indentAdjustment, $type, $subNodeName,
633
576
  $fixupInfo[$subNodeName] ?? null
634
577
  );
635
578
  if (null === $listResult) {
636
- return $this->pFallback($fallbackNode, $precedence, $lhsPrecedence);
579
+ return $this->pFallback($fallbackNode);
637
580
  }
638
581
 
639
582
  $result .= $listResult;
640
583
  continue;
641
584
  }
642
585
 
643
- // Check if this is a modifier change
644
- $key = $class . '->' . $subNodeName;
645
- if (!isset($this->modifierChangeMap[$key])) {
646
- return $this->pFallback($fallbackNode, $precedence, $lhsPrecedence);
586
+ if (is_int($subNode) && is_int($origSubNode)) {
587
+ // Check if this is a modifier change
588
+ $key = $type . '->' . $subNodeName;
589
+ if (!isset($this->modifierChangeMap[$key])) {
590
+ return $this->pFallback($fallbackNode);
591
+ }
592
+
593
+ $findToken = $this->modifierChangeMap[$key];
594
+ $result .= $this->pModifiers($subNode);
595
+ $pos = $this->origTokens->findRight($pos, $findToken);
596
+ continue;
647
597
  }
648
598
 
649
- [$printFn, $findToken] = $this->modifierChangeMap[$key];
650
- $result .= $this->$printFn($subNode);
651
- $pos = $this->origTokens->findRight($pos, $findToken);
652
- continue;
599
+ // If a non-node, non-array subnode changed, we don't be able to do a partial
600
+ // reconstructions, as we don't have enough offset information. Pretty print the
601
+ // whole node instead.
602
+ return $this->pFallback($fallbackNode);
653
603
  }
654
604
 
655
605
  $extraLeft = '';
@@ -667,7 +617,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
667
617
  // A node has been inserted, check if we have insertion information for it
668
618
  $key = $type . '->' . $subNodeName;
669
619
  if (!isset($this->insertionMap[$key])) {
670
- return $this->pFallback($fallbackNode, $precedence, $lhsPrecedence);
620
+ return $this->pFallback($fallbackNode);
671
621
  }
672
622
 
673
623
  list($findToken, $beforeToken, $extraLeft, $extraRight) = $this->insertionMap[$key];
@@ -689,7 +639,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
689
639
  // A node has been removed, check if we have removal information for it
690
640
  $key = $type . '->' . $subNodeName;
691
641
  if (!isset($this->removalMap[$key])) {
692
- return $this->pFallback($fallbackNode, $precedence, $lhsPrecedence);
642
+ return $this->pFallback($fallbackNode);
693
643
  }
694
644
 
695
645
  // Adjust positions to account for additional tokens that must be skipped
@@ -719,7 +669,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
719
669
  $fixup = $fixupInfo[$subNodeName];
720
670
  $res = $this->pFixup($fixup, $subNode, $class, $subStartPos, $subEndPos);
721
671
  } else {
722
- $res = $this->p($subNode, self::MAX_PRECEDENCE, self::MAX_PRECEDENCE, true);
672
+ $res = $this->p($subNode, true);
723
673
  }
724
674
 
725
675
  $this->safeAppend($result, $res);
@@ -738,23 +688,23 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
738
688
  /**
739
689
  * Perform a format-preserving pretty print of an array.
740
690
  *
741
- * @param Node[] $nodes New nodes
742
- * @param Node[] $origNodes Original nodes
743
- * @param int $pos Current token position (updated by reference)
744
- * @param int $indentAdjustment Adjustment for indentation
745
- * @param string $parentNodeClass Class of the containing node.
746
- * @param string $subNodeName Name of array subnode.
747
- * @param null|int $fixup Fixup information for array item nodes
691
+ * @param array $nodes New nodes
692
+ * @param array $origNodes Original nodes
693
+ * @param int $pos Current token position (updated by reference)
694
+ * @param int $indentAdjustment Adjustment for indentation
695
+ * @param string $parentNodeType Type of the containing node.
696
+ * @param string $subNodeName Name of array subnode.
697
+ * @param null|int $fixup Fixup information for array item nodes
748
698
  *
749
699
  * @return null|string Result of pretty print or null if cannot preserve formatting
750
700
  */
751
701
  protected function pArray(
752
- array $nodes, array $origNodes, int &$pos, int $indentAdjustment,
753
- string $parentNodeClass, string $subNodeName, ?int $fixup
754
- ): ?string {
702
+ array $nodes, array $origNodes, int &$pos, int $indentAdjustment,
703
+ string $parentNodeType, string $subNodeName, $fixup
704
+ ) {
755
705
  $diff = $this->nodeListDiffer->diffWithReplacements($origNodes, $nodes);
756
706
 
757
- $mapKey = $parentNodeClass . '->' . $subNodeName;
707
+ $mapKey = $parentNodeType . '->' . $subNodeName;
758
708
  $insertStr = $this->listInsertionMap[$mapKey] ?? null;
759
709
  $isStmtList = $subNodeName === 'stmts';
760
710
 
@@ -785,9 +735,9 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
785
735
  $result = '';
786
736
  foreach ($diff as $i => $diffElem) {
787
737
  $diffType = $diffElem->type;
788
- /** @var Node|string|null $arrItem */
738
+ /** @var Node|null $arrItem */
789
739
  $arrItem = $diffElem->new;
790
- /** @var Node|string|null $origArrItem */
740
+ /** @var Node|null $origArrItem */
791
741
  $origArrItem = $diffElem->old;
792
742
 
793
743
  if ($diffType === DiffElem::TYPE_KEEP || $diffType === DiffElem::TYPE_REPLACE) {
@@ -826,8 +776,9 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
826
776
  }
827
777
 
828
778
  if ($skipRemovedNode) {
829
- if ($isStmtList && $this->origTokens->haveTagInRange($pos, $itemStartPos)) {
830
- // We'd remove an opening/closing PHP tag.
779
+ if ($isStmtList && ($this->origTokens->haveBracesInRange($pos, $itemStartPos) ||
780
+ $this->origTokens->haveTagInRange($pos, $itemStartPos))) {
781
+ // We'd remove the brace of a code block.
831
782
  // TODO: Preserve formatting.
832
783
  $this->setIndentLevel($origIndentLevel);
833
784
  return null;
@@ -847,7 +798,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
847
798
  }
848
799
  }
849
800
 
850
- $this->safeAppend($result, $this->p($delayedAddNode, self::MAX_PRECEDENCE, self::MAX_PRECEDENCE, true));
801
+ $this->safeAppend($result, $this->p($delayedAddNode, true));
851
802
 
852
803
  if ($insertNewline) {
853
804
  $result .= $insertStr . $this->nl;
@@ -876,17 +827,10 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
876
827
  return null;
877
828
  }
878
829
 
879
- if (!$arrItem instanceof Node) {
880
- // We only support list insertion of nodes.
881
- return null;
882
- }
883
-
884
830
  // We go multiline if the original code was multiline,
885
831
  // or if it's an array item with a comment above it.
886
- // Match always uses multiline formatting.
887
832
  if ($insertStr === ', ' &&
888
- ($this->isMultiline($origNodes) || $arrItem->getComments() ||
889
- $parentNodeClass === Expr\Match_::class)
833
+ ($this->isMultiline($origNodes) || $arrItem->getComments())
890
834
  ) {
891
835
  $insertStr = ',';
892
836
  $insertNewline = true;
@@ -936,8 +880,9 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
936
880
  $pos, $itemStartPos, $indentAdjustment);
937
881
  $skipRemovedNode = true;
938
882
  } else {
939
- if ($isStmtList && $this->origTokens->haveTagInRange($pos, $itemStartPos)) {
940
- // We'd remove an opening/closing PHP tag.
883
+ if ($isStmtList && ($this->origTokens->haveBracesInRange($pos, $itemStartPos) ||
884
+ $this->origTokens->haveTagInRange($pos, $itemStartPos))) {
885
+ // We'd remove the brace of a code block.
941
886
  // TODO: Preserve formatting.
942
887
  return null;
943
888
  }
@@ -952,7 +897,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
952
897
  if (null !== $fixup && $arrItem->getAttribute('origNode') !== $origArrItem) {
953
898
  $res = $this->pFixup($fixup, $arrItem, null, $itemStartPos, $itemEndPos);
954
899
  } else {
955
- $res = $this->p($arrItem, self::MAX_PRECEDENCE, self::MAX_PRECEDENCE, true);
900
+ $res = $this->p($arrItem, true);
956
901
  }
957
902
  $this->safeAppend($result, $res);
958
903
 
@@ -986,7 +931,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
986
931
  $result .= $this->nl;
987
932
  }
988
933
  }
989
- $result .= $this->p($delayedAddNode, self::MAX_PRECEDENCE, self::MAX_PRECEDENCE, true);
934
+ $result .= $this->p($delayedAddNode, true);
990
935
  $first = false;
991
936
  }
992
937
  $result .= $extraRight === "\n" ? $this->nl : $extraRight;
@@ -1002,33 +947,22 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
1002
947
  * are required to preserve program semantics in a certain context (e.g. to maintain precedence
1003
948
  * or because only certain expressions are allowed in certain places).
1004
949
  *
1005
- * @param int $fixup Fixup type
1006
- * @param Node $subNode Subnode to print
950
+ * @param int $fixup Fixup type
951
+ * @param Node $subNode Subnode to print
1007
952
  * @param string|null $parentClass Class of parent node
1008
- * @param int $subStartPos Original start pos of subnode
1009
- * @param int $subEndPos Original end pos of subnode
953
+ * @param int $subStartPos Original start pos of subnode
954
+ * @param int $subEndPos Original end pos of subnode
1010
955
  *
1011
956
  * @return string Result of fixed-up print of subnode
1012
957
  */
1013
- protected function pFixup(int $fixup, Node $subNode, ?string $parentClass, int $subStartPos, int $subEndPos): string {
958
+ protected function pFixup(int $fixup, Node $subNode, $parentClass, int $subStartPos, int $subEndPos) : string {
1014
959
  switch ($fixup) {
1015
960
  case self::FIXUP_PREC_LEFT:
1016
- // We use a conservative approximation where lhsPrecedence == precedence.
1017
- if (!$this->origTokens->haveParens($subStartPos, $subEndPos)) {
1018
- $precedence = $this->precedenceMap[$parentClass][1];
1019
- return $this->p($subNode, $precedence, $precedence);
1020
- }
1021
- break;
1022
961
  case self::FIXUP_PREC_RIGHT:
1023
962
  if (!$this->origTokens->haveParens($subStartPos, $subEndPos)) {
1024
- $precedence = $this->precedenceMap[$parentClass][2];
1025
- return $this->p($subNode, $precedence, $precedence);
1026
- }
1027
- break;
1028
- case self::FIXUP_PREC_UNARY:
1029
- if (!$this->origTokens->haveParens($subStartPos, $subEndPos)) {
1030
- $precedence = $this->precedenceMap[$parentClass][0];
1031
- return $this->p($subNode, $precedence, $precedence);
963
+ list($precedence, $associativity) = $this->precedenceMap[$parentClass];
964
+ return $this->pPrec($subNode, $precedence, $associativity,
965
+ $fixup === self::FIXUP_PREC_LEFT ? -1 : 1);
1032
966
  }
1033
967
  break;
1034
968
  case self::FIXUP_CALL_LHS:
@@ -1068,7 +1002,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
1068
1002
  }
1069
1003
  break;
1070
1004
  case self::FIXUP_ENCAPSED:
1071
- if (!$subNode instanceof Node\InterpolatedStringPart
1005
+ if (!$subNode instanceof Scalar\EncapsedStringPart
1072
1006
  && !$this->origTokens->haveBraces($subStartPos, $subEndPos)
1073
1007
  ) {
1074
1008
  return '{' . $this->p($subNode) . '}';
@@ -1087,8 +1021,11 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
1087
1021
  *
1088
1022
  * Example: "echo" and "$x" result in "echo$x", but "echo" and "x" result in "echo x".
1089
1023
  * Without safeAppend the result would be "echox", which does not preserve semantics.
1024
+ *
1025
+ * @param string $str
1026
+ * @param string $append
1090
1027
  */
1091
- protected function safeAppend(string &$str, string $append): void {
1028
+ protected function safeAppend(string &$str, string $append) {
1092
1029
  if ($str === "") {
1093
1030
  $str = $append;
1094
1031
  return;
@@ -1113,7 +1050,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
1113
1050
  *
1114
1051
  * @return bool Whether parentheses are required
1115
1052
  */
1116
- protected function callLhsRequiresParens(Node $node): bool {
1053
+ protected function callLhsRequiresParens(Node $node) : bool {
1117
1054
  return !($node instanceof Node\Name
1118
1055
  || $node instanceof Expr\Variable
1119
1056
  || $node instanceof Expr\ArrayDimFetch
@@ -1131,7 +1068,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
1131
1068
  *
1132
1069
  * @return bool Whether parentheses are required
1133
1070
  */
1134
- protected function dereferenceLhsRequiresParens(Node $node): bool {
1071
+ protected function dereferenceLhsRequiresParens(Node $node) : bool {
1135
1072
  // A constant can occur on the LHS of an array/object deref, but not a static deref.
1136
1073
  return $this->staticDereferenceLhsRequiresParens($node)
1137
1074
  && !$node instanceof Expr\ConstFetch;
@@ -1189,18 +1126,14 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
1189
1126
  *
1190
1127
  * @return string Printed modifiers
1191
1128
  */
1192
- protected function pModifiers(int $modifiers): string {
1193
- return ($modifiers & Modifiers::FINAL ? 'final ' : '')
1194
- . ($modifiers & Modifiers::ABSTRACT ? 'abstract ' : '')
1195
- . ($modifiers & Modifiers::PUBLIC ? 'public ' : '')
1196
- . ($modifiers & Modifiers::PROTECTED ? 'protected ' : '')
1197
- . ($modifiers & Modifiers::PRIVATE ? 'private ' : '')
1198
- . ($modifiers & Modifiers::STATIC ? 'static ' : '')
1199
- . ($modifiers & Modifiers::READONLY ? 'readonly ' : '');
1200
- }
1201
-
1202
- protected function pStatic(bool $static): string {
1203
- return $static ? 'static ' : '';
1129
+ protected function pModifiers(int $modifiers) {
1130
+ return ($modifiers & Stmt\Class_::MODIFIER_PUBLIC ? 'public ' : '')
1131
+ . ($modifiers & Stmt\Class_::MODIFIER_PROTECTED ? 'protected ' : '')
1132
+ . ($modifiers & Stmt\Class_::MODIFIER_PRIVATE ? 'private ' : '')
1133
+ . ($modifiers & Stmt\Class_::MODIFIER_STATIC ? 'static ' : '')
1134
+ . ($modifiers & Stmt\Class_::MODIFIER_ABSTRACT ? 'abstract ' : '')
1135
+ . ($modifiers & Stmt\Class_::MODIFIER_FINAL ? 'final ' : '')
1136
+ . ($modifiers & Stmt\Class_::MODIFIER_READONLY ? 'readonly ' : '');
1204
1137
  }
1205
1138
 
1206
1139
  /**
@@ -1210,7 +1143,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
1210
1143
  *
1211
1144
  * @return bool Whether multiline formatting is used
1212
1145
  */
1213
- protected function isMultiline(array $nodes): bool {
1146
+ protected function isMultiline(array $nodes) : bool {
1214
1147
  if (\count($nodes) < 2) {
1215
1148
  return false;
1216
1149
  }
@@ -1242,19 +1175,15 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
1242
1175
  *
1243
1176
  * The label char map determines whether a certain character may occur in a label.
1244
1177
  */
1245
- protected function initializeLabelCharMap(): void {
1246
- if (isset($this->labelCharMap)) {
1247
- return;
1248
- }
1178
+ protected function initializeLabelCharMap() {
1179
+ if ($this->labelCharMap) return;
1249
1180
 
1250
1181
  $this->labelCharMap = [];
1251
1182
  for ($i = 0; $i < 256; $i++) {
1183
+ // Since PHP 7.1 The lower range is 0x80. However, we also want to support code for
1184
+ // older versions.
1252
1185
  $chr = chr($i);
1253
- $this->labelCharMap[$chr] = $i >= 0x80 || ctype_alnum($chr);
1254
- }
1255
-
1256
- if ($this->phpVersion->allowsDelInIdentifiers()) {
1257
- $this->labelCharMap["\x7f"] = true;
1186
+ $this->labelCharMap[$chr] = $i >= 0x7f || ctype_alnum($chr);
1258
1187
  }
1259
1188
  }
1260
1189
 
@@ -1263,10 +1192,8 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
1263
1192
  *
1264
1193
  * The node list differ is used to determine differences between two array subnodes.
1265
1194
  */
1266
- protected function initializeNodeListDiffer(): void {
1267
- if (isset($this->nodeListDiffer)) {
1268
- return;
1269
- }
1195
+ protected function initializeNodeListDiffer() {
1196
+ if ($this->nodeListDiffer) return;
1270
1197
 
1271
1198
  $this->nodeListDiffer = new Internal\Differ(function ($a, $b) {
1272
1199
  if ($a instanceof Node && $b instanceof Node) {
@@ -1283,21 +1210,22 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
1283
1210
  * The fixup map is used to determine whether a certain subnode of a certain node may require
1284
1211
  * some kind of "fixup" operation, e.g. the addition of parenthesis or braces.
1285
1212
  */
1286
- protected function initializeFixupMap(): void {
1287
- if (isset($this->fixupMap)) {
1288
- return;
1289
- }
1213
+ protected function initializeFixupMap() {
1214
+ if ($this->fixupMap) return;
1290
1215
 
1291
1216
  $this->fixupMap = [
1217
+ Expr\PreInc::class => ['var' => self::FIXUP_PREC_RIGHT],
1218
+ Expr\PreDec::class => ['var' => self::FIXUP_PREC_RIGHT],
1219
+ Expr\PostInc::class => ['var' => self::FIXUP_PREC_LEFT],
1220
+ Expr\PostDec::class => ['var' => self::FIXUP_PREC_LEFT],
1292
1221
  Expr\Instanceof_::class => [
1293
- 'expr' => self::FIXUP_PREC_UNARY,
1222
+ 'expr' => self::FIXUP_PREC_LEFT,
1294
1223
  'class' => self::FIXUP_NEW,
1295
1224
  ],
1296
1225
  Expr\Ternary::class => [
1297
1226
  'cond' => self::FIXUP_PREC_LEFT,
1298
1227
  'else' => self::FIXUP_PREC_RIGHT,
1299
1228
  ],
1300
- Expr\Yield_::class => ['value' => self::FIXUP_PREC_UNARY],
1301
1229
 
1302
1230
  Expr\FuncCall::class => ['name' => self::FIXUP_CALL_LHS],
1303
1231
  Expr\StaticCall::class => ['class' => self::FIXUP_STATIC_DEREF_LHS],
@@ -1327,7 +1255,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
1327
1255
  'var' => self::FIXUP_DEREF_LHS,
1328
1256
  'name' => self::FIXUP_BRACED_NAME,
1329
1257
  ],
1330
- Scalar\InterpolatedString::class => [
1258
+ Scalar\Encapsed::class => [
1331
1259
  'parts' => self::FIXUP_ENCAPSED,
1332
1260
  ],
1333
1261
  ];
@@ -1350,19 +1278,27 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
1350
1278
  ];
1351
1279
  }
1352
1280
 
1281
+ $assignOps = [
1282
+ Expr\Assign::class, Expr\AssignRef::class, AssignOp\Plus::class, AssignOp\Minus::class,
1283
+ AssignOp\Mul::class, AssignOp\Div::class, AssignOp\Concat::class, AssignOp\Mod::class,
1284
+ AssignOp\BitwiseAnd::class, AssignOp\BitwiseOr::class, AssignOp\BitwiseXor::class,
1285
+ AssignOp\ShiftLeft::class, AssignOp\ShiftRight::class, AssignOp\Pow::class, AssignOp\Coalesce::class
1286
+ ];
1287
+ foreach ($assignOps as $assignOp) {
1288
+ $this->fixupMap[$assignOp] = [
1289
+ 'var' => self::FIXUP_PREC_LEFT,
1290
+ 'expr' => self::FIXUP_PREC_RIGHT,
1291
+ ];
1292
+ }
1293
+
1353
1294
  $prefixOps = [
1354
- Expr\Clone_::class, Expr\BitwiseNot::class, Expr\BooleanNot::class, Expr\UnaryPlus::class, Expr\UnaryMinus::class,
1295
+ Expr\BitwiseNot::class, Expr\BooleanNot::class, Expr\UnaryPlus::class, Expr\UnaryMinus::class,
1355
1296
  Cast\Int_::class, Cast\Double::class, Cast\String_::class, Cast\Array_::class,
1356
1297
  Cast\Object_::class, Cast\Bool_::class, Cast\Unset_::class, Expr\ErrorSuppress::class,
1357
1298
  Expr\YieldFrom::class, Expr\Print_::class, Expr\Include_::class,
1358
- Expr\Assign::class, Expr\AssignRef::class, AssignOp\Plus::class, AssignOp\Minus::class,
1359
- AssignOp\Mul::class, AssignOp\Div::class, AssignOp\Concat::class, AssignOp\Mod::class,
1360
- AssignOp\BitwiseAnd::class, AssignOp\BitwiseOr::class, AssignOp\BitwiseXor::class,
1361
- AssignOp\ShiftLeft::class, AssignOp\ShiftRight::class, AssignOp\Pow::class, AssignOp\Coalesce::class,
1362
- Expr\ArrowFunction::class, Expr\Throw_::class,
1363
1299
  ];
1364
1300
  foreach ($prefixOps as $prefixOp) {
1365
- $this->fixupMap[$prefixOp] = ['expr' => self::FIXUP_PREC_UNARY];
1301
+ $this->fixupMap[$prefixOp] = ['expr' => self::FIXUP_PREC_RIGHT];
1366
1302
  }
1367
1303
  }
1368
1304
 
@@ -1372,10 +1308,8 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
1372
1308
  * The removal map is used to determine which additional tokens should be removed when a
1373
1309
  * certain node is replaced by null.
1374
1310
  */
1375
- protected function initializeRemovalMap(): void {
1376
- if (isset($this->removalMap)) {
1377
- return;
1378
- }
1311
+ protected function initializeRemovalMap() {
1312
+ if ($this->removalMap) return;
1379
1313
 
1380
1314
  $stripBoth = ['left' => \T_WHITESPACE, 'right' => \T_WHITESPACE];
1381
1315
  $stripLeft = ['left' => \T_WHITESPACE];
@@ -1385,7 +1319,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
1385
1319
  $stripEquals = ['left' => '='];
1386
1320
  $this->removalMap = [
1387
1321
  'Expr_ArrayDimFetch->dim' => $stripBoth,
1388
- 'ArrayItem->key' => $stripDoubleArrow,
1322
+ 'Expr_ArrayItem->key' => $stripDoubleArrow,
1389
1323
  'Expr_ArrowFunction->returnType' => $stripColon,
1390
1324
  'Expr_Closure->returnType' => $stripColon,
1391
1325
  'Expr_Exit->expr' => $stripBoth,
@@ -1408,7 +1342,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
1408
1342
  'Stmt_If->else' => $stripLeft,
1409
1343
  'Stmt_Namespace->name' => $stripLeft,
1410
1344
  'Stmt_Property->type' => $stripRight,
1411
- 'PropertyItem->default' => $stripEquals,
1345
+ 'Stmt_PropertyProperty->default' => $stripEquals,
1412
1346
  'Stmt_Return->expr' => $stripBoth,
1413
1347
  'Stmt_StaticVar->default' => $stripEquals,
1414
1348
  'Stmt_TraitUseAdaptation_Alias->newName' => $stripLeft,
@@ -1420,18 +1354,16 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
1420
1354
  ];
1421
1355
  }
1422
1356
 
1423
- protected function initializeInsertionMap(): void {
1424
- if (isset($this->insertionMap)) {
1425
- return;
1426
- }
1357
+ protected function initializeInsertionMap() {
1358
+ if ($this->insertionMap) return;
1427
1359
 
1428
1360
  // TODO: "yield" where both key and value are inserted doesn't work
1429
1361
  // [$find, $beforeToken, $extraLeft, $extraRight]
1430
1362
  $this->insertionMap = [
1431
1363
  'Expr_ArrayDimFetch->dim' => ['[', false, null, null],
1432
- 'ArrayItem->key' => [null, false, null, ' => '],
1433
- 'Expr_ArrowFunction->returnType' => [')', false, ': ', null],
1434
- 'Expr_Closure->returnType' => [')', false, ': ', null],
1364
+ 'Expr_ArrayItem->key' => [null, false, null, ' => '],
1365
+ 'Expr_ArrowFunction->returnType' => [')', false, ' : ', null],
1366
+ 'Expr_Closure->returnType' => [')', false, ' : ', null],
1435
1367
  'Expr_Ternary->if' => ['?', false, ' ', ' '],
1436
1368
  'Expr_Yield->key' => [\T_YIELD, false, null, ' => '],
1437
1369
  'Expr_Yield->value' => [\T_YIELD, false, ' ', null],
@@ -1439,19 +1371,19 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
1439
1371
  'Param->default' => [null, false, ' = ', null],
1440
1372
  'Stmt_Break->num' => [\T_BREAK, false, ' ', null],
1441
1373
  'Stmt_Catch->var' => [null, false, ' ', null],
1442
- 'Stmt_ClassMethod->returnType' => [')', false, ': ', null],
1374
+ 'Stmt_ClassMethod->returnType' => [')', false, ' : ', null],
1443
1375
  'Stmt_ClassConst->type' => [\T_CONST, false, ' ', null],
1444
1376
  'Stmt_Class->extends' => [null, false, ' extends ', null],
1445
1377
  'Stmt_Enum->scalarType' => [null, false, ' : ', null],
1446
1378
  'Stmt_EnumCase->expr' => [null, false, ' = ', null],
1447
- 'Expr_PrintableNewAnonClass->extends' => [null, false, ' extends ', null],
1379
+ 'Expr_PrintableNewAnonClass->extends' => [null, ' extends ', null],
1448
1380
  'Stmt_Continue->num' => [\T_CONTINUE, false, ' ', null],
1449
1381
  'Stmt_Foreach->keyVar' => [\T_AS, false, null, ' => '],
1450
- 'Stmt_Function->returnType' => [')', false, ': ', null],
1382
+ 'Stmt_Function->returnType' => [')', false, ' : ', null],
1451
1383
  'Stmt_If->else' => [null, false, ' ', null],
1452
1384
  'Stmt_Namespace->name' => [\T_NAMESPACE, false, ' ', null],
1453
1385
  'Stmt_Property->type' => [\T_VARIABLE, true, null, ' '],
1454
- 'PropertyItem->default' => [null, false, ' = ', null],
1386
+ 'Stmt_PropertyProperty->default' => [null, false, ' = ', null],
1455
1387
  'Stmt_Return->expr' => [\T_RETURN, false, ' ', null],
1456
1388
  'Stmt_StaticVar->default' => [null, false, ' = ', null],
1457
1389
  //'Stmt_TraitUseAdaptation_Alias->newName' => [T_AS, false, ' ', null], // TODO
@@ -1465,139 +1397,132 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
1465
1397
  ];
1466
1398
  }
1467
1399
 
1468
- protected function initializeListInsertionMap(): void {
1469
- if (isset($this->listInsertionMap)) {
1470
- return;
1471
- }
1400
+ protected function initializeListInsertionMap() {
1401
+ if ($this->listInsertionMap) return;
1472
1402
 
1473
1403
  $this->listInsertionMap = [
1474
1404
  // special
1475
1405
  //'Expr_ShellExec->parts' => '', // TODO These need to be treated more carefully
1476
- //'Scalar_InterpolatedString->parts' => '',
1477
- Stmt\Catch_::class . '->types' => '|',
1478
- UnionType::class . '->types' => '|',
1479
- IntersectionType::class . '->types' => '&',
1480
- Stmt\If_::class . '->elseifs' => ' ',
1481
- Stmt\TryCatch::class . '->catches' => ' ',
1406
+ //'Scalar_Encapsed->parts' => '',
1407
+ 'Stmt_Catch->types' => '|',
1408
+ 'UnionType->types' => '|',
1409
+ 'IntersectionType->types' => '&',
1410
+ 'Stmt_If->elseifs' => ' ',
1411
+ 'Stmt_TryCatch->catches' => ' ',
1482
1412
 
1483
1413
  // comma-separated lists
1484
- Expr\Array_::class . '->items' => ', ',
1485
- Expr\ArrowFunction::class . '->params' => ', ',
1486
- Expr\Closure::class . '->params' => ', ',
1487
- Expr\Closure::class . '->uses' => ', ',
1488
- Expr\FuncCall::class . '->args' => ', ',
1489
- Expr\Isset_::class . '->vars' => ', ',
1490
- Expr\List_::class . '->items' => ', ',
1491
- Expr\MethodCall::class . '->args' => ', ',
1492
- Expr\NullsafeMethodCall::class . '->args' => ', ',
1493
- Expr\New_::class . '->args' => ', ',
1494
- PrintableNewAnonClassNode::class . '->args' => ', ',
1495
- Expr\StaticCall::class . '->args' => ', ',
1496
- Stmt\ClassConst::class . '->consts' => ', ',
1497
- Stmt\ClassMethod::class . '->params' => ', ',
1498
- Stmt\Class_::class . '->implements' => ', ',
1499
- Stmt\Enum_::class . '->implements' => ', ',
1500
- PrintableNewAnonClassNode::class . '->implements' => ', ',
1501
- Stmt\Const_::class . '->consts' => ', ',
1502
- Stmt\Declare_::class . '->declares' => ', ',
1503
- Stmt\Echo_::class . '->exprs' => ', ',
1504
- Stmt\For_::class . '->init' => ', ',
1505
- Stmt\For_::class . '->cond' => ', ',
1506
- Stmt\For_::class . '->loop' => ', ',
1507
- Stmt\Function_::class . '->params' => ', ',
1508
- Stmt\Global_::class . '->vars' => ', ',
1509
- Stmt\GroupUse::class . '->uses' => ', ',
1510
- Stmt\Interface_::class . '->extends' => ', ',
1511
- Expr\Match_::class . '->arms' => ', ',
1512
- Stmt\Property::class . '->props' => ', ',
1513
- Stmt\StaticVar::class . '->vars' => ', ',
1514
- Stmt\TraitUse::class . '->traits' => ', ',
1515
- Stmt\TraitUseAdaptation\Precedence::class . '->insteadof' => ', ',
1516
- Stmt\Unset_::class . '->vars' => ', ',
1517
- Stmt\UseUse::class . '->uses' => ', ',
1518
- MatchArm::class . '->conds' => ', ',
1519
- AttributeGroup::class . '->attrs' => ', ',
1414
+ 'Expr_Array->items' => ', ',
1415
+ 'Expr_ArrowFunction->params' => ', ',
1416
+ 'Expr_Closure->params' => ', ',
1417
+ 'Expr_Closure->uses' => ', ',
1418
+ 'Expr_FuncCall->args' => ', ',
1419
+ 'Expr_Isset->vars' => ', ',
1420
+ 'Expr_List->items' => ', ',
1421
+ 'Expr_MethodCall->args' => ', ',
1422
+ 'Expr_NullsafeMethodCall->args' => ', ',
1423
+ 'Expr_New->args' => ', ',
1424
+ 'Expr_PrintableNewAnonClass->args' => ', ',
1425
+ 'Expr_StaticCall->args' => ', ',
1426
+ 'Stmt_ClassConst->consts' => ', ',
1427
+ 'Stmt_ClassMethod->params' => ', ',
1428
+ 'Stmt_Class->implements' => ', ',
1429
+ 'Stmt_Enum->implements' => ', ',
1430
+ 'Expr_PrintableNewAnonClass->implements' => ', ',
1431
+ 'Stmt_Const->consts' => ', ',
1432
+ 'Stmt_Declare->declares' => ', ',
1433
+ 'Stmt_Echo->exprs' => ', ',
1434
+ 'Stmt_For->init' => ', ',
1435
+ 'Stmt_For->cond' => ', ',
1436
+ 'Stmt_For->loop' => ', ',
1437
+ 'Stmt_Function->params' => ', ',
1438
+ 'Stmt_Global->vars' => ', ',
1439
+ 'Stmt_GroupUse->uses' => ', ',
1440
+ 'Stmt_Interface->extends' => ', ',
1441
+ 'Stmt_Match->arms' => ', ',
1442
+ 'Stmt_Property->props' => ', ',
1443
+ 'Stmt_StaticVar->vars' => ', ',
1444
+ 'Stmt_TraitUse->traits' => ', ',
1445
+ 'Stmt_TraitUseAdaptation_Precedence->insteadof' => ', ',
1446
+ 'Stmt_Unset->vars' => ', ',
1447
+ 'Stmt_Use->uses' => ', ',
1448
+ 'MatchArm->conds' => ', ',
1449
+ 'AttributeGroup->attrs' => ', ',
1520
1450
 
1521
1451
  // statement lists
1522
- Expr\Closure::class . '->stmts' => "\n",
1523
- Stmt\Case_::class . '->stmts' => "\n",
1524
- Stmt\Catch_::class . '->stmts' => "\n",
1525
- Stmt\Class_::class . '->stmts' => "\n",
1526
- Stmt\Enum_::class . '->stmts' => "\n",
1527
- PrintableNewAnonClassNode::class . '->stmts' => "\n",
1528
- Stmt\Interface_::class . '->stmts' => "\n",
1529
- Stmt\Trait_::class . '->stmts' => "\n",
1530
- Stmt\ClassMethod::class . '->stmts' => "\n",
1531
- Stmt\Declare_::class . '->stmts' => "\n",
1532
- Stmt\Do_::class . '->stmts' => "\n",
1533
- Stmt\ElseIf_::class . '->stmts' => "\n",
1534
- Stmt\Else_::class . '->stmts' => "\n",
1535
- Stmt\Finally_::class . '->stmts' => "\n",
1536
- Stmt\Foreach_::class . '->stmts' => "\n",
1537
- Stmt\For_::class . '->stmts' => "\n",
1538
- Stmt\Function_::class . '->stmts' => "\n",
1539
- Stmt\If_::class . '->stmts' => "\n",
1540
- Stmt\Namespace_::class . '->stmts' => "\n",
1541
- Stmt\Block::class . '->stmts' => "\n",
1542
-
1543
- // Attribute groups
1544
- Stmt\Class_::class . '->attrGroups' => "\n",
1545
- Stmt\Enum_::class . '->attrGroups' => "\n",
1546
- Stmt\EnumCase::class . '->attrGroups' => "\n",
1547
- Stmt\Interface_::class . '->attrGroups' => "\n",
1548
- Stmt\Trait_::class . '->attrGroups' => "\n",
1549
- Stmt\Function_::class . '->attrGroups' => "\n",
1550
- Stmt\ClassMethod::class . '->attrGroups' => "\n",
1551
- Stmt\ClassConst::class . '->attrGroups' => "\n",
1552
- Stmt\Property::class . '->attrGroups' => "\n",
1553
- PrintableNewAnonClassNode::class . '->attrGroups' => ' ',
1554
- Expr\Closure::class . '->attrGroups' => ' ',
1555
- Expr\ArrowFunction::class . '->attrGroups' => ' ',
1556
- Param::class . '->attrGroups' => ' ',
1557
- Stmt\Switch_::class . '->cases' => "\n",
1558
- Stmt\TraitUse::class . '->adaptations' => "\n",
1559
- Stmt\TryCatch::class . '->stmts' => "\n",
1560
- Stmt\While_::class . '->stmts' => "\n",
1452
+ 'Expr_Closure->stmts' => "\n",
1453
+ 'Stmt_Case->stmts' => "\n",
1454
+ 'Stmt_Catch->stmts' => "\n",
1455
+ 'Stmt_Class->stmts' => "\n",
1456
+ 'Stmt_Enum->stmts' => "\n",
1457
+ 'Expr_PrintableNewAnonClass->stmts' => "\n",
1458
+ 'Stmt_Interface->stmts' => "\n",
1459
+ 'Stmt_Trait->stmts' => "\n",
1460
+ 'Stmt_ClassMethod->stmts' => "\n",
1461
+ 'Stmt_Declare->stmts' => "\n",
1462
+ 'Stmt_Do->stmts' => "\n",
1463
+ 'Stmt_ElseIf->stmts' => "\n",
1464
+ 'Stmt_Else->stmts' => "\n",
1465
+ 'Stmt_Finally->stmts' => "\n",
1466
+ 'Stmt_Foreach->stmts' => "\n",
1467
+ 'Stmt_For->stmts' => "\n",
1468
+ 'Stmt_Function->stmts' => "\n",
1469
+ 'Stmt_If->stmts' => "\n",
1470
+ 'Stmt_Namespace->stmts' => "\n",
1471
+ 'Stmt_Class->attrGroups' => "\n",
1472
+ 'Stmt_Enum->attrGroups' => "\n",
1473
+ 'Stmt_EnumCase->attrGroups' => "\n",
1474
+ 'Stmt_Interface->attrGroups' => "\n",
1475
+ 'Stmt_Trait->attrGroups' => "\n",
1476
+ 'Stmt_Function->attrGroups' => "\n",
1477
+ 'Stmt_ClassMethod->attrGroups' => "\n",
1478
+ 'Stmt_ClassConst->attrGroups' => "\n",
1479
+ 'Stmt_Property->attrGroups' => "\n",
1480
+ 'Expr_PrintableNewAnonClass->attrGroups' => ' ',
1481
+ 'Expr_Closure->attrGroups' => ' ',
1482
+ 'Expr_ArrowFunction->attrGroups' => ' ',
1483
+ 'Param->attrGroups' => ' ',
1484
+ 'Stmt_Switch->cases' => "\n",
1485
+ 'Stmt_TraitUse->adaptations' => "\n",
1486
+ 'Stmt_TryCatch->stmts' => "\n",
1487
+ 'Stmt_While->stmts' => "\n",
1561
1488
 
1562
1489
  // dummy for top-level context
1563
1490
  'File->stmts' => "\n",
1564
1491
  ];
1565
1492
  }
1566
1493
 
1567
- protected function initializeEmptyListInsertionMap(): void {
1568
- if (isset($this->emptyListInsertionMap)) {
1569
- return;
1570
- }
1494
+ protected function initializeEmptyListInsertionMap() {
1495
+ if ($this->emptyListInsertionMap) return;
1571
1496
 
1572
1497
  // TODO Insertion into empty statement lists.
1573
1498
 
1574
1499
  // [$find, $extraLeft, $extraRight]
1575
1500
  $this->emptyListInsertionMap = [
1576
- Expr\ArrowFunction::class . '->params' => ['(', '', ''],
1577
- Expr\Closure::class . '->uses' => [')', ' use (', ')'],
1578
- Expr\Closure::class . '->params' => ['(', '', ''],
1579
- Expr\FuncCall::class . '->args' => ['(', '', ''],
1580
- Expr\MethodCall::class . '->args' => ['(', '', ''],
1581
- Expr\NullsafeMethodCall::class . '->args' => ['(', '', ''],
1582
- Expr\New_::class . '->args' => ['(', '', ''],
1583
- PrintableNewAnonClassNode::class . '->args' => ['(', '', ''],
1584
- PrintableNewAnonClassNode::class . '->implements' => [null, ' implements ', ''],
1585
- Expr\StaticCall::class . '->args' => ['(', '', ''],
1586
- Stmt\Class_::class . '->implements' => [null, ' implements ', ''],
1587
- Stmt\Enum_::class . '->implements' => [null, ' implements ', ''],
1588
- Stmt\ClassMethod::class . '->params' => ['(', '', ''],
1589
- Stmt\Interface_::class . '->extends' => [null, ' extends ', ''],
1590
- Stmt\Function_::class . '->params' => ['(', '', ''],
1591
- Stmt\Interface_::class . '->attrGroups' => [null, '', "\n"],
1592
- Stmt\Class_::class . '->attrGroups' => [null, '', "\n"],
1593
- Stmt\ClassConst::class . '->attrGroups' => [null, '', "\n"],
1594
- Stmt\ClassMethod::class . '->attrGroups' => [null, '', "\n"],
1595
- Stmt\Function_::class . '->attrGroups' => [null, '', "\n"],
1596
- Stmt\Property::class . '->attrGroups' => [null, '', "\n"],
1597
- Stmt\Trait_::class . '->attrGroups' => [null, '', "\n"],
1598
- Expr\ArrowFunction::class . '->attrGroups' => [null, '', ' '],
1599
- Expr\Closure::class . '->attrGroups' => [null, '', ' '],
1600
- PrintableNewAnonClassNode::class . '->attrGroups' => [\T_NEW, ' ', ''],
1501
+ 'Expr_ArrowFunction->params' => ['(', '', ''],
1502
+ 'Expr_Closure->uses' => [')', ' use(', ')'],
1503
+ 'Expr_Closure->params' => ['(', '', ''],
1504
+ 'Expr_FuncCall->args' => ['(', '', ''],
1505
+ 'Expr_MethodCall->args' => ['(', '', ''],
1506
+ 'Expr_NullsafeMethodCall->args' => ['(', '', ''],
1507
+ 'Expr_New->args' => ['(', '', ''],
1508
+ 'Expr_PrintableNewAnonClass->args' => ['(', '', ''],
1509
+ 'Expr_PrintableNewAnonClass->implements' => [null, ' implements ', ''],
1510
+ 'Expr_StaticCall->args' => ['(', '', ''],
1511
+ 'Stmt_Class->implements' => [null, ' implements ', ''],
1512
+ 'Stmt_Enum->implements' => [null, ' implements ', ''],
1513
+ 'Stmt_ClassMethod->params' => ['(', '', ''],
1514
+ 'Stmt_Interface->extends' => [null, ' extends ', ''],
1515
+ 'Stmt_Function->params' => ['(', '', ''],
1516
+ 'Stmt_Interface->attrGroups' => [null, '', "\n"],
1517
+ 'Stmt_Class->attrGroups' => [null, '', "\n"],
1518
+ 'Stmt_ClassConst->attrGroups' => [null, '', "\n"],
1519
+ 'Stmt_ClassMethod->attrGroups' => [null, '', "\n"],
1520
+ 'Stmt_Function->attrGroups' => [null, '', "\n"],
1521
+ 'Stmt_Property->attrGroups' => [null, '', "\n"],
1522
+ 'Stmt_Trait->attrGroups' => [null, '', "\n"],
1523
+ 'Expr_ArrowFunction->attrGroups' => [null, '', ' '],
1524
+ 'Expr_Closure->attrGroups' => [null, '', ' '],
1525
+ 'Expr_PrintableNewAnonClass->attrGroups' => [\T_NEW, ' ', ''],
1601
1526
 
1602
1527
  /* These cannot be empty to start with:
1603
1528
  * Expr_Isset->vars
@@ -1629,27 +1554,23 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
1629
1554
  ];
1630
1555
  }
1631
1556
 
1632
- protected function initializeModifierChangeMap(): void {
1633
- if (isset($this->modifierChangeMap)) {
1634
- return;
1635
- }
1557
+ protected function initializeModifierChangeMap() {
1558
+ if ($this->modifierChangeMap) return;
1636
1559
 
1637
1560
  $this->modifierChangeMap = [
1638
- Stmt\ClassConst::class . '->flags' => ['pModifiers', \T_CONST],
1639
- Stmt\ClassMethod::class . '->flags' => ['pModifiers', \T_FUNCTION],
1640
- Stmt\Class_::class . '->flags' => ['pModifiers', \T_CLASS],
1641
- Stmt\Property::class . '->flags' => ['pModifiers', \T_VARIABLE],
1642
- PrintableNewAnonClassNode::class . '->flags' => ['pModifiers', \T_CLASS],
1643
- Param::class . '->flags' => ['pModifiers', \T_VARIABLE],
1644
- Expr\Closure::class . '->static' => ['pStatic', \T_FUNCTION],
1645
- Expr\ArrowFunction::class . '->static' => ['pStatic', \T_FN],
1646
- //Stmt\TraitUseAdaptation\Alias::class . '->newModifier' => 0, // TODO
1561
+ 'Stmt_ClassConst->flags' => \T_CONST,
1562
+ 'Stmt_ClassMethod->flags' => \T_FUNCTION,
1563
+ 'Stmt_Class->flags' => \T_CLASS,
1564
+ 'Stmt_Property->flags' => \T_VARIABLE,
1565
+ 'Expr_PrintableNewAnonClass->flags' => \T_CLASS,
1566
+ 'Param->flags' => \T_VARIABLE,
1567
+ //'Stmt_TraitUseAdaptation_Alias->newModifier' => 0, // TODO
1647
1568
  ];
1648
1569
 
1649
1570
  // List of integer subnodes that are not modifiers:
1650
1571
  // Expr_Include->type
1651
1572
  // Stmt_GroupUse->type
1652
1573
  // Stmt_Use->type
1653
- // UseItem->type
1574
+ // Stmt_UseUse->type
1654
1575
  }
1655
1576
  }