MCPcopy Create free account
hub / github.com/PHPantom-dev/phpantom_lsp / demo

Method demo

examples/demo.php:2970–3018  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2968class InlayHintsDemo
2969{
2970 public function demo(): void
2971 {
2972 // Parameter name hints appear before each argument:
2973 $user = createUser('Alice', 'test@example.com'); // name:, email:
2974
2975 // By-reference parameters show & before the name:
2976 $arr = [1, 2, 3];
2977 $this->modify($arr, 'ascending'); // &data:, direction:
2978
2979 // Hints are suppressed when variable name matches parameter:
2980 $needle = 'search term';
2981 $this->search($needle, 10); // (no hint for $needle), limit:
2982
2983 // Constructor calls also get hints:
2984 $recipe = new Recipe('Cake', [new Ingredient('flour', 2)]); // name:, ingredients:
2985
2986 // Static method calls:
2987 User::findByEmail('alice@example.com'); // email:
2988
2989 // Chained method calls:
2990 $pen = Pen::make('blue'); // color:
2991 $pen->rename('Sky Blue'); // name:
2992
2993 // ── Closure / arrow function hints ─────────────────────────
2994 // When a closure or arrow function is passed to a callable-typed
2995 // parameter, PHPantom infers types from the callable signature.
2996 // Untyped params show the inferred type before $var, and the
2997 // return type shows after the closing parenthesis.
2998
2999 // Arrow function: "User " before $u, ": string" after parens.
3000 $names = $this->mapUsers(fn($u) => $u->name);
3001
3002 // Long-form closure gets the same treatment:
3003 $upper = $this->mapUsers(function ($u) {
3004 return strtoupper($u->name);
3005 });
3006
3007 // Partial typing: only the untyped $b gets a hint.
3008 $sum2 = $this->reduce(fn(int $a, $b) => $a + $b);
3009
3010 // Already-typed parameters and return types get no hint:
3011 $emails = $this->mapUsers(fn(User $u): string => $u->email);
3012
3013 // Standalone functions with callable params work too:
3014 $doubled = $this->transformItems([1, 2, 3], fn($x) => $x * 2);
3015
3016 // Method call context — filter shows "Order " before $o, ": bool" after.
3017 $big = $this->filterOrders(fn($o) => $o->isAdmin);
3018 }
3019
3020 /** @param array<int> &$data */
3021 public function modify(array &$data, string $direction): void {}

Callers

nothing calls this directly

Calls 10

modifyMethod · 0.95
searchMethod · 0.95
mapUsersMethod · 0.95
reduceMethod · 0.95
transformItemsMethod · 0.95
filterOrdersMethod · 0.95
createUserFunction · 0.85
findByEmailMethod · 0.80
makeMethod · 0.45
renameMethod · 0.45

Tested by

no test coverage detected