insertionOfNullable.test 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. }
  43. foreach (
  44. $x
  45. as
  46. $y
  47. ) {}
  48. static
  49. $var
  50. ;
  51. try {
  52. } catch (X
  53. $y) {
  54. }
  55. if ($cond) { // Foo
  56. } elseif ($cond2) { // Bar
  57. }
  58. -----
  59. $stmts[0]->returnType = new Node\Name('Foo');
  60. $stmts[0]->params[0]->type = new Node\Identifier('int');
  61. $stmts[0]->params[1]->type = new Node\Identifier('array');
  62. $stmts[0]->params[1]->default = new Expr\ConstFetch(new Node\Name('null'));
  63. $stmts[1]->expr->dim = new Expr\Variable('a');
  64. $stmts[2]->expr->items[0]->key = new Scalar\String_('X');
  65. $stmts[3]->expr->returnType = new Node\Name('Bar');
  66. $stmts[4]->expr->if = new Expr\Variable('z');
  67. $stmts[5]->expr->key = new Expr\Variable('k');
  68. $stmts[6]->expr->value = new Expr\Variable('v');
  69. $stmts[7]->num = new Scalar\LNumber(2);
  70. $stmts[8]->num = new Scalar\LNumber(2);
  71. $stmts[9]->expr = new Expr\Variable('x');
  72. $stmts[10]->extends = new Node\Name\FullyQualified('Bar');
  73. $stmts[10]->stmts[0]->returnType = new Node\Name('Y');
  74. $stmts[10]->stmts[1]->props[0]->default = new Scalar\DNumber(42.0);
  75. $stmts[11]->keyVar = new Expr\Variable('z');
  76. $stmts[12]->vars[0]->default = new Scalar\String_('abc');
  77. $stmts[13]->finally = new Stmt\Finally_([]);
  78. $stmts[14]->else = new Stmt\Else_([]);
  79. -----
  80. <?php
  81. // TODO: The result spacing isn't always optimal. We may want to skip whitespace in some cases.
  82. function
  83. foo(
  84. int $x,
  85. array &$y = null
  86. ) : Foo
  87. {}
  88. $foo
  89. [$a
  90. ];
  91. [
  92. 'X' => $value
  93. ];
  94. function
  95. () : Bar
  96. {};
  97. $x
  98. ? $z
  99. :
  100. $y;
  101. yield
  102. $k => $v ;
  103. yield $v ;
  104. break 2
  105. ;
  106. continue 2
  107. ;
  108. return $x
  109. ;
  110. class
  111. X extends \Bar
  112. {
  113. public
  114. function y() : Y
  115. {}
  116. private
  117. $x = 42.0
  118. ;
  119. }
  120. foreach (
  121. $x
  122. as
  123. $z => $y
  124. ) {}
  125. static
  126. $var = 'abc'
  127. ;
  128. try {
  129. } catch (X
  130. $y) {
  131. } finally {
  132. }
  133. if ($cond) { // Foo
  134. } elseif ($cond2) { // Bar
  135. } else {
  136. }
  137. -----
  138. <?php
  139. namespace
  140. { echo 42; }
  141. -----
  142. $stmts[0]->name = new Node\Name('Foo');
  143. -----
  144. <?php
  145. namespace Foo
  146. { echo 42; }