torture.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Services;
  4. use App\Contracts\Logger;
  5. use App\Contracts\Cache as CacheAlias;
  6. use Countable;
  7. use function App\Helpers\format_id;
  8. use const App\Config\MAX_TRIES;
  9. use App\Models\{User, Post as PostAlias, Sub\Deep};
  10. require 'lib/plain.php';
  11. require_once('lib/parens.php');
  12. include 'lib/inc.php';
  13. include_once 'lib/inc_once.php';
  14. require __DIR__ . '/dynamic.php';
  15. const TOP_LEVEL_MAX = 10;
  16. // non-ASCII before a symbol: café ünïcode line
  17. function top_helper(?Logger $log, User|PostAlias $u, Logger&Countable $lc, (Foo&Bar)|Baz $dnf, \App\Models\User $qual, string $s, int ...$rest): UserModel
  18. {
  19. top_body_call();
  20. return new UserModel();
  21. }
  22. /** Doc for Documented. */
  23. #[Registry(param: Logger::class)]
  24. class Documented extends BaseThing implements HasColor, \JsonSerializable
  25. {
  26. use SoftDeletes, Notify\Deeper;
  27. use ConflictA, ConflictB {
  28. ConflictA::greet insteadof ConflictB;
  29. ConflictB::greet as protected greetB;
  30. }
  31. const MULTI_A = 1, MULTI_B = 2;
  32. final public const int TYPED_MAX = 5;
  33. public ?Logger $logger, $fallback;
  34. private CacheAlias|string $union;
  35. protected static iterable $registry;
  36. public readonly int $count;
  37. var $legacy;
  38. final public Foo $finalTyped;
  39. public function __construct(private Logger $promoted, protected string $name = 'x', ICache $plain = new NullMailer())
  40. {
  41. }
  42. /** Doc over attribute. */
  43. #[Route('/x')]
  44. public function withAttr(): void
  45. {
  46. }
  47. public static function make(): static
  48. {
  49. return new static();
  50. }
  51. public function selfRet(): self
  52. {
  53. return $this;
  54. }
  55. public function nullableRet(): ?Logger
  56. {
  57. return null;
  58. }
  59. public function unionRet(): Foo|Bar
  60. {
  61. return new Foo();
  62. }
  63. protected function callsZoo($x, User $u, $obj, $var, $cls, $arr, $a)
  64. {
  65. helper();
  66. \App\Helpers\format_id(1);
  67. App\Helpers\other(2);
  68. $x->m1();
  69. $this->m2();
  70. $this->prop->m3();
  71. $this->a->b->m4();
  72. $obj->prop->m5();
  73. UserModel::query();
  74. self::sHelper();
  75. static::sHelper();
  76. parent::pHelper();
  77. $var::vm();
  78. \Qual\Cls::qm();
  79. UserModel::factory($x)->where('a');
  80. $this->factory($x)->go();
  81. foo()->fluent();
  82. $a?->maybe()->chained();
  83. "chain"->upper();
  84. $fn = 'x';
  85. $fn();
  86. ($x)('arg');
  87. strlen(...);
  88. $this->m2(...);
  89. Cls::sm(...);
  90. new UserModel();
  91. new \App\Models\User();
  92. new Models\User(1);
  93. new static();
  94. new self();
  95. new parent();
  96. new $cls();
  97. $anon = new class extends BaseAnon implements IAnon {
  98. public function anonMethod(): void
  99. {
  100. inner_anon_call();
  101. }
  102. };
  103. new Widget(make_arg());
  104. $m = match ($x) {
  105. 1 => one_case(),
  106. default => other_case(),
  107. };
  108. $$x = 5;
  109. $interp = "{$this->x} and $u prefix";
  110. $here = <<<EOT
  111. heredoc {$this->y} text
  112. EOT;
  113. $now = <<<'EOT'
  114. nowdoc plain
  115. EOT;
  116. echo SomeCls::CONST_READ;
  117. $clsName = UserModel::class;
  118. $propRead = UserModel::$conn;
  119. $rel = self::REL_CONST;
  120. $qualRead = \Qual\Cls::QCONST;
  121. $suit = Suit::Hearts;
  122. }
  123. public function nester($arr, $x): void
  124. {
  125. function innerNamed(): void
  126. {
  127. inner_call();
  128. }
  129. if (!class_exists('Poly')) {
  130. class Poly
  131. {
  132. const POLY_MAX = 3;
  133. public function pm(): void
  134. {
  135. poly_call();
  136. }
  137. }
  138. }
  139. $c = function () use (&$x) {
  140. closure_call();
  141. };
  142. $a = fn ($v) => arrow_call($v);
  143. usort($arr, 'cmp_items');
  144. array_map('App\Svc\namespaced_fn', $arr);
  145. call_user_func([$this, 'm2']);
  146. call_user_func([UserModel::class, 'sm']);
  147. call_user_func(['Cls', 'sm']);
  148. register_shutdown_function('Cls::shutdown');
  149. $x->map('not_captured');
  150. plain_call('not_a_hof_string');
  151. }
  152. public function reader(): int
  153. {
  154. $sum = MULTI_A + TYPED_MAX;
  155. $s = "interp TYPED_MAX read: {$this->x} MULTI_B";
  156. $varOccurrence = $MULTI_A;
  157. return $sum + self::TYPED_MAX;
  158. }
  159. }
  160. interface Shape extends Base1, Base2, \Qual\Base3
  161. {
  162. public function area(): float;
  163. const SHAPE_KIND = 'geo';
  164. }
  165. trait SoftDeletes
  166. {
  167. const TRAIT_CONST = 1;
  168. public function restore(): void
  169. {
  170. $this->doRestore();
  171. }
  172. }
  173. enum Suit: string implements HasColor
  174. {
  175. case Hearts = 'H';
  176. case Spades = 'S';
  177. const ENUM_MAX = 4;
  178. public function color(): string
  179. {
  180. return enum_color($this);
  181. }
  182. }
  183. enum Pure
  184. {
  185. case A;
  186. case B;
  187. }
  188. abstract class AbstractBase
  189. {
  190. abstract protected function hook(): void;
  191. }