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

Method demo

examples/demo.php:1096–1126  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1094class ClosureInvocationDemo
1095{
1096 public function demo(): void
1097 {
1098 // Closure literal with native return type hint
1099 $makePen = function(): Pen { return new Pen(); };
1100 $makePen()->write(); // resolves Pen from closure return type
1101
1102 // Arrow function literal
1103 $makePencil = fn(): Pencil => new Pencil();
1104 $makePencil()->sketch(); // arrow fn return type
1105
1106 // Docblock callable annotation
1107 /** @var \Closure(): Pencil $supplier */
1108 $supplier = getUnknownValue();
1109 $supplier()->sharpen(); // @var Closure() annotation
1110
1111 // Chaining after callable invocation
1112 $builder = function(): Pen { return new Pen(); };
1113 $builder()->rename('Bold')->write(); // chain after $fn()
1114
1115 // Variable assigned from callable invocation
1116 $fromClosure = $makePen();
1117 $fromClosure->write(); // $result = $fn() resolves return type
1118
1119 // Immediately invoked arrow function with return type
1120 $result = (fn(): Pen => new Pen())();
1121 $result->write(); // resolves Pen from arrow fn return type
1122
1123 // Immediately invoked closure with return type
1124 $obj = (function(): Pencil { return new Pencil(); })();
1125 $obj->sketch(); // resolves Pencil from closure return type
1126 }
1127}
1128
1129

Callers

nothing calls this directly

Calls 5

getUnknownValueFunction · 0.85
writeMethod · 0.80
sketchMethod · 0.80
sharpenMethod · 0.80
renameMethod · 0.45

Tested by

no test coverage detected