insertionOfNullable.test 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. Insertion of a nullable node
  2. -----
  3. <?php
  4. // TODO: The result spacing isn't always optimal. We may want to skip whitespace in some cases.
  5. function
  6. foo(
  7. $x,
  8. &$y
  9. )
  10. {}
  11. $foo
  12. [
  13. ];
  14. [
  15. $value
  16. ];
  17. function
  18. ()
  19. {};
  20. $x
  21. ?
  22. :
  23. $y;
  24. yield
  25. $v ;
  26. yield ;
  27. break
  28. ;
  29. continue
  30. ;
  31. return
  32. ;
  33. class
  34. X
  35. {
  36. public
  37. function y()
  38. {}
  39. private
  40. $x
  41. ;
  42. const
  43. X
  44. = 1;
  45. }
  46. foreach (
  47. $x
  48. as
  49. $y
  50. ) {}
  51. static
  52. $var
  53. ;
  54. try {
  55. } catch (X
  56. $y) {
  57. }
  58. if ($cond) { // Foo
  59. } elseif ($cond2) { // Bar
  60. }
  61. -----
  62. $stmts[0]->returnType = new Node\Name('Foo');
  63. $stmts[0]->params[0]->type = new Node\Identifier('int');
  64. $stmts[0]->params[1]->type = new Node\Identifier('array');
  65. $stmts[0]->params[1]->default = new Expr\ConstFetch(new Node\Name('null'));
  66. $stmts[1]->expr->dim = new Expr\Variable('a');
  67. $stmts[2]->expr->items[0]->key = new Scalar\String_('X');
  68. $stmts[3]->expr->returnType = new Node\Name('Bar');
  69. $stmts[4]->expr->if = new Expr\Variable('z');
  70. $stmts[5]->expr->key = new Expr\Variable('k');
  71. $stmts[6]->expr->value = new Expr\Variable('v');
  72. $stmts[7]->num = new Scalar\LNumber(2);
  73. $stmts[8]->num = new Scalar\LNumber(2);
  74. $stmts[9]->expr = new Expr\Variable('x');
  75. $stmts[10]->extends = new Node\Name\FullyQualified('Bar');
  76. $stmts[10]->stmts[0]->returnType = new Node\Name('Y');
  77. $stmts[10]->stmts[1]->props[0]->default = new Scalar\DNumber(42.0);
  78. $stmts[10]->stmts[2]->type = new Node\Identifier('int');
  79. $stmts[11]->keyVar = new Expr\Variable('z');
  80. $stmts[12]->vars[0]->default = new Scalar\String_('abc');
  81. $stmts[13]->finally = new Stmt\Finally_([]);
  82. $stmts[14]->else = new Stmt\Else_([]);
  83. -----
  84. <?php
  85. // TODO: The result spacing isn't always optimal. We may want to skip whitespace in some cases.
  86. function
  87. foo(
  88. int $x,
  89. array &$y = null
  90. ) : Foo
  91. {}
  92. $foo
  93. [$a
  94. ];
  95. [
  96. 'X' => $value
  97. ];
  98. function
  99. () : Bar
  100. {};
  101. $x
  102. ? $z
  103. :
  104. $y;
  105. yield
  106. $k => $v ;
  107. yield $v ;
  108. break 2
  109. ;
  110. continue 2
  111. ;
  112. return $x
  113. ;
  114. class
  115. X extends \Bar
  116. {
  117. public
  118. function y() : Y
  119. {}
  120. private
  121. $x = 42.0
  122. ;
  123. const int
  124. X
  125. = 1;
  126. }
  127. foreach (
  128. $x
  129. as
  130. $z => $y
  131. ) {}
  132. static
  133. $var = 'abc'
  134. ;
  135. try {
  136. } catch (X
  137. $y) {
  138. } finally {
  139. }
  140. if ($cond) { // Foo
  141. } elseif ($cond2) { // Bar
  142. } else {
  143. }
  144. -----
  145. <?php
  146. namespace
  147. { echo 42; }
  148. -----
  149. $stmts[0]->name = new Node\Name('Foo');
  150. -----
  151. <?php
  152. namespace Foo
  153. { echo 42; }
  154. -----
  155. <?php
  156. try
  157. {
  158. }
  159. catch (Exception)
  160. {
  161. }
  162. -----
  163. $stmts[0]->catches[0]->var = new Expr\Variable('e');
  164. -----
  165. <?php
  166. try
  167. {
  168. }
  169. catch (Exception $e)
  170. {
  171. }