Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

feat(php-lsp): @return $this/static, if-condition call walk, +50 tests

Martin Vogel20dd651a2ed9
diff --git a/internal/cbm/lsp/generated/php_stdlib_data.c b/internal/cbm/lsp/generated/php_stdlib_data.c
index dda7068fe..1854824a8 100644
--- a/internal/cbm/lsp/generated/php_stdlib_data.c
+++ b/internal/cbm/lsp/generated/php_stdlib_data.c
@@ -536,9 +536,150 @@ void cbm_php_stdlib_register(CBMTypeRegistry *reg, CBMArena *arena) {
REG_METHOD(em, "firstOrCreate", self);
}
- /* ── \Generator (return type from yield) ──────────────────── */
- REG_TYPE("Generator", "Generator", false, generator_parents);
- /* Generator extends Iterator → Iterator methods already registered. */
+ /* (Generator already registered in the SPL section above.) */
+
+ /* ── Symfony Cache ─────────────────────────────────────── */
+ static const char *cache_parents[] = {NULL};
+ REG_TYPE("Symfony.Contracts.Cache.CacheInterface", "CacheInterface", true, cache_parents);
+ REG_TYPE("Symfony.Contracts.Cache.ItemInterface", "ItemInterface", true, cache_parents);
+ REG_TYPE("Psr.Cache.CacheItemPoolInterface", "CacheItemPoolInterface", true, cache_parents);
+ REG_TYPE("Psr.Cache.CacheItemInterface", "CacheItemInterface", true, cache_parents);
+ REG_METHOD("Symfony.Contracts.Cache.CacheInterface", "get", MIXED);
+ REG_METHOD("Symfony.Contracts.Cache.CacheInterface", "delete", cbm_type_builtin(arena, "bool"));
+ REG_METHOD("Symfony.Contracts.Cache.ItemInterface", "set",
+ cbm_type_named(arena, "Symfony.Contracts.Cache.ItemInterface"));
+ REG_METHOD("Symfony.Contracts.Cache.ItemInterface", "expiresAfter",
+ cbm_type_named(arena, "Symfony.Contracts.Cache.ItemInterface"));
+ REG_METHOD("Symfony.Contracts.Cache.ItemInterface", "get", MIXED);
+ REG_METHOD("Psr.Cache.CacheItemPoolInterface", "getItem",
+ cbm_type_named(arena, "Psr.Cache.CacheItemInterface"));
+ REG_METHOD("Psr.Cache.CacheItemPoolInterface", "save",
+ cbm_type_builtin(arena, "bool"));
+ REG_METHOD("Psr.Cache.CacheItemInterface", "get", MIXED);
+ REG_METHOD("Psr.Cache.CacheItemInterface", "set",
+ cbm_type_named(arena, "Psr.Cache.CacheItemInterface"));
+
+ /* ── Symfony EventDispatcher ────────────────────────────── */
+ static const char *event_parents[] = {NULL};
+ REG_TYPE("Symfony.Contracts.EventDispatcher.EventDispatcherInterface",
+ "EventDispatcherInterface", true, event_parents);
+ REG_TYPE("Symfony.Contracts.EventDispatcher.Event", "Event", false, event_parents);
+ REG_METHOD("Symfony.Contracts.EventDispatcher.EventDispatcherInterface", "dispatch", MIXED);
+
+ /* ── Symfony Mailer ─────────────────────────────────────── */
+ static const char *mailer_parents[] = {NULL};
+ REG_TYPE("Symfony.Component.Mailer.MailerInterface", "MailerInterface", true, mailer_parents);
+ REG_TYPE("Symfony.Component.Mime.Email", "Email", false, mailer_parents);
+ REG_METHOD("Symfony.Component.Mailer.MailerInterface", "send",
+ cbm_type_builtin(arena, "void"));
+ {
+ const char *e = "Symfony.Component.Mime.Email";
+ const CBMType *self = cbm_type_named(arena, "Symfony.Component.Mime.Email");
+ REG_METHOD(e, "from", self);
+ REG_METHOD(e, "to", self);
+ REG_METHOD(e, "cc", self);
+ REG_METHOD(e, "bcc", self);
+ REG_METHOD(e, "subject", self);
+ REG_METHOD(e, "text", self);
+ REG_METHOD(e, "html", self);
+ REG_METHOD(e, "attachFromPath", self);
+ }
+
+ /* ── Symfony Validator ─────────────────────────────────── */
+ static const char *validator_parents[] = {NULL};
+ REG_TYPE("Symfony.Component.Validator.Validator.ValidatorInterface", "ValidatorInterface",
+ true, validator_parents);
+ REG_TYPE("Symfony.Component.Validator.ConstraintViolationListInterface",
+ "ConstraintViolationListInterface", true, validator_parents);
+ REG_METHOD("Symfony.Component.Validator.Validator.ValidatorInterface", "validate",
+ cbm_type_named(arena,
+ "Symfony.Component.Validator.ConstraintViolationListInterface"));
+ REG_METHOD("Symfony.Component.Validator.ConstraintViolationListInterface", "count",
+ cbm_type_builtin(arena, "int"));
+
+ /* ── Laravel HTTP Request / Response ──────────────────── */
+ static const char *laravel_request_parents[] = {"Symfony.Component.HttpFoundation.Request",
+ NULL};
+ REG_TYPE("Illuminate.Http.Request", "Request", false, laravel_request_parents);
+ REG_TYPE("Illuminate.Http.Response", "Response", false, laravel_request_parents);
+ REG_TYPE("Illuminate.Http.JsonResponse", "JsonResponse", false, laravel_request_parents);
+ REG_METHOD("Illuminate.Http.Request", "input", MIXED);
+ REG_METHOD("Illuminate.Http.Request", "query", MIXED);
+ REG_METHOD("Illuminate.Http.Request", "all", cbm_type_builtin(arena, "array"));
+ REG_METHOD("Illuminate.Http.Request", "user", MIXED);
+ REG_METHOD("Illuminate.Http.Request", "validate", cbm_type_builtin(arena, "array"));
+ REG_METHOD("Illuminate.Http.Response", "header",
+ cbm_type_named(arena, "Illuminate.Http.Response"));
+ REG_METHOD("Illuminate.Http.Response", "withHeaders",
+ cbm_type_named(arena, "Illuminate.Http.Response"));
+ REG_METHOD("Illuminate.Http.JsonResponse", "header",
+ cbm_type_named(arena, "Illuminate.Http.JsonResponse"));
+
+ /* ── Laravel Auth ─────────────────────────────────────── */
+ static const char *auth_parents[] = {NULL};
+ REG_TYPE("Illuminate.Contracts.Auth.Authenticatable", "Authenticatable", true,
+ auth_parents);
+ REG_TYPE("Illuminate.Contracts.Auth.Guard", "Guard", true, auth_parents);
+ REG_METHOD("Illuminate.Contracts.Auth.Authenticatable", "getAuthIdentifier", MIXED);
+ REG_METHOD("Illuminate.Contracts.Auth.Authenticatable", "getAuthPassword",
+ cbm_type_builtin(arena, "string"));
+ REG_METHOD("Illuminate.Contracts.Auth.Guard", "user",
+ cbm_type_named(arena, "Illuminate.Contracts.Auth.Authenticatable"));
+ REG_METHOD("Illuminate.Contracts.Auth.Guard", "check", cbm_type_builtin(arena, "bool"));
+ REG_METHOD("Illuminate.Contracts.Auth.Guard", "id", MIXED);
+
+ /* ── Laravel Session / View ──────────────────────────── */
+ static const char *session_parents[] = {NULL};
+ REG_TYPE("Illuminate.Contracts.Session.Session", "Session", true, session_parents);
+ REG_METHOD("Illuminate.Contracts.Session.Session", "get", MIXED);
+ REG_METHOD("Illuminate.Contracts.Session.Session", "put", cbm_type_builtin(arena, "void"));
+ REG_METHOD("Illuminate.Contracts.Session.Session", "has", cbm_type_builtin(arena, "bool"));
+ REG_METHOD("Illuminate.Contracts.Session.Session", "flash", cbm_type_builtin(arena, "void"));
+
+ REG_TYPE("Illuminate.View.View", "View", false, session_parents);
+ REG_METHOD("Illuminate.View.View", "render", cbm_type_builtin(arena, "string"));
+ REG_METHOD("Illuminate.View.View", "with",
+ cbm_type_named(arena, "Illuminate.View.View"));
+
+ /* ── ReactPHP / Promise ───────────────────────────────── */
+ static const char *promise_parents[] = {NULL};
+ REG_TYPE("React.Promise.PromiseInterface", "PromiseInterface", true, promise_parents);
+ REG_TYPE("GuzzleHttp.Promise.PromiseInterface", "PromiseInterface", true, promise_parents);
+ REG_METHOD("React.Promise.PromiseInterface", "then",
+ cbm_type_named(arena, "React.Promise.PromiseInterface"));
+ REG_METHOD("React.Promise.PromiseInterface", "catch",
+ cbm_type_named(arena, "React.Promise.PromiseInterface"));
+ REG_METHOD("React.Promise.PromiseInterface", "finally",
+ cbm_type_named(arena, "React.Promise.PromiseInterface"));
+ REG_METHOD("GuzzleHttp.Promise.PromiseInterface", "then",
+ cbm_type_named(arena, "GuzzleHttp.Promise.PromiseInterface"));
+
+ /* ── Monolog (popular logger) ───────────────────────── */
+ static const char *monolog_parents[] = {"Psr.Log.LoggerInterface", NULL};
+ REG_TYPE("Monolog.Logger", "Logger", false, monolog_parents);
+ /* Logger inherits info/warning/error/etc. methods from PSR LoggerInterface. */
+ REG_METHOD("Monolog.Logger", "pushHandler",
+ cbm_type_named(arena, "Monolog.Logger"));
+ REG_METHOD("Monolog.Logger", "pushProcessor",
+ cbm_type_named(arena, "Monolog.Logger"));
+
+ /* ── Reflection API ──────────────────────────────────── */
+ static const char *reflection_parents[] = {NULL};
+ REG_TYPE("ReflectionClass", "ReflectionClass", false, reflection_parents);
+ REG_TYPE("ReflectionMethod", "ReflectionMethod", false, reflection_parents);
+ REG_TYPE("ReflectionProperty", "ReflectionProperty", false, reflection_parents);
+ REG_TYPE("ReflectionFunction", "ReflectionFunction", false, reflection_parents);
+ REG_METHOD("ReflectionClass", "getName", cbm_type_builtin(arena, "string"));
+ REG_METHOD("ReflectionClass", "getMethods", cbm_type_builtin(arena, "array"));
+ REG_METHOD("ReflectionClass", "getMethod",
+ cbm_type_named(arena, "ReflectionMethod"));
+ REG_METHOD("ReflectionClass", "newInstance", MIXED);
+ REG_METHOD("ReflectionClass", "newInstanceArgs", MIXED);
+ REG_METHOD("ReflectionMethod", "invoke", MIXED);
+ REG_METHOD("ReflectionMethod", "invokeArgs", MIXED);
+ REG_METHOD("ReflectionMethod", "getName", cbm_type_builtin(arena, "string"));
+ REG_METHOD("ReflectionProperty", "getValue", MIXED);
+ REG_METHOD("ReflectionProperty", "setValue", cbm_type_builtin(arena, "void"));
}
#undef REG_TYPE
diff --git a/internal/cbm/lsp/php_lsp.c b/internal/cbm/lsp/php_lsp.c
index fedfda6ad..c6892338a 100644
--- a/internal/cbm/lsp/php_lsp.c
+++ b/internal/cbm/lsp/php_lsp.c
@@ -174,16 +174,17 @@ static const char *find_use(PHPLSPContext *ctx, const char *local_name, int kind
* Returns an arena-allocated string in dotted form. May return NULL for builtins. */
const char *php_resolve_class_name(PHPLSPContext *ctx, const char *name) {
if (!name || !*name) return NULL;
- if (php_is_builtin_type_name(name)) return NULL;
- /* Self / static / parent are resolved by caller; still translate here for
- * cases where they slip through. */
+ /* Self / static / parent are class-relative pseudo-types and must be
+ * checked BEFORE the builtin-name check, since they're listed as
+ * builtins above for type-parsing purposes. */
if (strcmp(name, "self") == 0 || strcmp(name, "static") == 0) {
return ctx->enclosing_class_qn;
}
if (strcmp(name, "parent") == 0) {
return ctx->enclosing_parent_qn;
}
+ if (php_is_builtin_type_name(name)) return NULL;
/* Fully-qualified — leading backslash. */
if (name[0] == '\\') {
@@ -1852,6 +1853,9 @@ static void process_if_statement(PHPLSPContext *ctx, TSNode node) {
if (!past_cond) {
if (strcmp(k, "parenthesized_expression") == 0) {
past_cond = true;
+ /* Walk the condition expression so calls inside it (e.g.
+ * `$it->valid()` in `if ($it->valid())`) get resolved. */
+ php_resolve_calls_in_node(ctx, c);
continue;
}
/* Non-condition child encountered before the condition: keep walking. */
@@ -3178,10 +3182,20 @@ static void process_class_for_fields(PHPLSPContext *ctx, CBMTypeRegistry *reg,
/* Re-parse the declared return type via php_parse_type_node so
* generic forms like `\Generator<int, User>` end up as
* TEMPLATE types, not broken NAMED("Generator<int, User>")
- * that the simpler parse_return_type_text produced earlier. */
+ * that the simpler parse_return_type_text produced earlier.
+ *
+ * We temporarily set ctx->enclosing_class_qn so that
+ * `self`/`static` in the return-type position resolve to the
+ * current class. */
TSNode rt_node = ts_node_child_by_field_name(c, "return_type", 11);
if (!ts_node_is_null(rt_node) && mn) {
+ const char *saved_class = ctx->enclosing_class_qn;
+ const char *saved_parent = ctx->enclosing_parent_qn;
+ ctx->enclosing_class_qn = cqn;
+ /* ctx->enclosing_parent_qn left as-is (best-effort). */
const CBMType *parsed = php_parse_type_node(ctx, rt_node);
+ ctx->enclosing_class_qn = saved_class;
+ ctx->enclosing_parent_qn = saved_parent;
if (parsed && parsed->kind != CBM_TYPE_UNKNOWN) {
for (int fi = 0; fi < reg->func_count; fi++) {
CBMRegisteredFunc *rf = &reg->funcs[fi];
@@ -3224,9 +3238,18 @@ static void process_class_for_fields(PHPLSPContext *ctx, CBMTypeRegistry *reg,
char *type_text = cbm_arena_strndup(ctx->arena, type_start,
(size_t)(p - type_start));
const CBMType *ret_t = NULL;
- /* First: does the raw token match a class @template
+ /* `@return $this` / `@return static` / `@return self`
+ * → return the enclosing class type. Critical for
+ * fluent-builder chains. */
+ if (strcmp(type_text, "$this") == 0 ||
+ strcmp(type_text, "static") == 0 ||
+ strcmp(type_text, "self") == 0) {
+ ret_t = cbm_type_named(ctx->arena, cqn);
+ }
+ /* Else: does the raw token match a class @template
* param name? If so, build NAMED(name) so call-site
* substitution can rewrite it later. */
+ if (!ret_t)
for (int t = 0; t < reg->type_count; t++) {
if (strcmp(reg->types[t].qualified_name, cqn) != 0)
continue;
diff --git a/tests/test_php_lsp.c b/tests/test_php_lsp.c
index 25eb29aa4..1bcdcd3c7 100644
--- a/tests/test_php_lsp.c
+++ b/tests/test_php_lsp.c
@@ -2929,6 +2929,1001 @@ TEST(phplsp_magic_get_set) {
PASS();
}
+/* ── 151. @return $this fluent chain ─────────────────────── */
+
+TEST(phplsp_at_return_this_fluent) {
+ const char *src =
+ "<?php\n"
+ "class Builder {\n"
+ " /** @return $this */\n"
+ " public function where($a, $b) { return $this; }\n"
+ " /** @return $this */\n"
+ " public function orderBy($k) { return $this; }\n"
+ " public function get(): array { return []; }\n"
+ "}\n"
+ "class C {\n"
+ " public function run(Builder $b): void {\n"
+ " $b->where('a', 1)->orderBy('id')->get();\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "Builder.where") >= 0);
+ ASSERT(find_resolved(r, "C.run", "Builder.orderBy") >= 0);
+ ASSERT(find_resolved(r, "C.run", "Builder.get") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 152. @return static (covariant return) ───────────── */
+
+TEST(phplsp_at_return_static_covariant) {
+ const char *src =
+ "<?php\n"
+ "class Base {\n"
+ " /** @return static */\n"
+ " public function self() { return $this; }\n"
+ "}\n"
+ "class Kid extends Base { public function ext(): int { return 1; } }\n"
+ "class C {\n"
+ " public function run(Kid $k): void { $k->self()->ext(); }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ /* @return static — at least .self() resolves; .ext() may or may not
+ * depending on covariance handling. */
+ ASSERT(find_resolved(r, "C.run", ".self") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 153. Symfony Cache get ───────────────────────────── */
+
+TEST(phplsp_symfony_cache) {
+ const char *src =
+ "<?php\n"
+ "class C {\n"
+ " public function run(\\Symfony\\Contracts\\Cache\\CacheInterface $c): void {\n"
+ " $c->get('key', fn() => 'value');\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "CacheInterface.get") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 154. Symfony EventDispatcher dispatch ───────────── */
+
+TEST(phplsp_event_dispatcher) {
+ const char *src =
+ "<?php\n"
+ "class C {\n"
+ " public function run(\\Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface $d): void {\n"
+ " $d->dispatch(new \\Symfony\\Contracts\\EventDispatcher\\Event());\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "EventDispatcherInterface.dispatch") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 155. Symfony Mailer chain ────────────────────────── */
+
+TEST(phplsp_mailer_chain) {
+ const char *src =
+ "<?php\n"
+ "class C {\n"
+ " public function run(\\Symfony\\Component\\Mailer\\MailerInterface $m): void {\n"
+ " $email = (new \\Symfony\\Component\\Mime\\Email())\n"
+ " ->from('a@b')\n"
+ " ->to('c@d')\n"
+ " ->subject('hi');\n"
+ " $m->send($email);\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "Email.from") >= 0);
+ ASSERT(find_resolved(r, "C.run", "Email.to") >= 0);
+ ASSERT(find_resolved(r, "C.run", "Email.subject") >= 0);
+ ASSERT(find_resolved(r, "C.run", "MailerInterface.send") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 156. Laravel Request input/validate ─────────────── */
+
+TEST(phplsp_laravel_request) {
+ const char *src =
+ "<?php\n"
+ "class C {\n"
+ " public function run(\\Illuminate\\Http\\Request $req): void {\n"
+ " $req->input('name');\n"
+ " $req->validate(['a' => 'required']);\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "Request.input") >= 0);
+ ASSERT(find_resolved(r, "C.run", "Request.validate") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 157. Laravel Auth user chain ────────────────────── */
+
+TEST(phplsp_laravel_auth) {
+ const char *src =
+ "<?php\n"
+ "class C {\n"
+ " public function run(\\Illuminate\\Contracts\\Auth\\Guard $auth): void {\n"
+ " $auth->user()->getAuthIdentifier();\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "Guard.user") >= 0);
+ ASSERT(find_resolved(r, "C.run", "Authenticatable.getAuthIdentifier") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 158. Laravel View render ────────────────────── */
+
+TEST(phplsp_laravel_view) {
+ const char *src =
+ "<?php\n"
+ "class C {\n"
+ " public function run(\\Illuminate\\View\\View $v): string {\n"
+ " return $v->with('x', 1)->render();\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "View.with") >= 0);
+ ASSERT(find_resolved(r, "C.run", "View.render") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 159. ReactPHP Promise ───────────────────────── */
+
+TEST(phplsp_promise_chain) {
+ const char *src =
+ "<?php\n"
+ "class C {\n"
+ " public function run(\\React\\Promise\\PromiseInterface $p): void {\n"
+ " $p->then(fn() => null)->catch(fn() => null);\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "PromiseInterface.then") >= 0);
+ ASSERT(find_resolved(r, "C.run", "PromiseInterface.catch") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 160. Monolog logger from PSR ─────────────── */
+
+TEST(phplsp_monolog_logger) {
+ const char *src =
+ "<?php\n"
+ "class C {\n"
+ " public function run(\\Monolog\\Logger $log): void {\n"
+ " $log->info('msg');\n"
+ " $log->pushHandler('h')->pushProcessor('p');\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", ".info") >= 0);
+ ASSERT(find_resolved(r, "C.run", "Logger.pushHandler") >= 0);
+ ASSERT(find_resolved(r, "C.run", "Logger.pushProcessor") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 161. Reflection API ───────────────────────── */
+
+TEST(phplsp_reflection_class) {
+ const char *src =
+ "<?php\n"
+ "class C {\n"
+ " public function run(\\ReflectionClass $rc): void {\n"
+ " $rc->getMethod('foo')->invoke($rc->newInstance());\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "ReflectionClass.getMethod") >= 0);
+ ASSERT(find_resolved(r, "C.run", "ReflectionMethod.invoke") >= 0);
+ ASSERT(find_resolved(r, "C.run", "ReflectionClass.newInstance") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 162. Validator validate ─────────────────── */
+
+TEST(phplsp_validator) {
+ const char *src =
+ "<?php\n"
+ "class C {\n"
+ " public function run(\\Symfony\\Component\\Validator\\Validator\\ValidatorInterface $v): void {\n"
+ " $v->validate('input')->count();\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "ValidatorInterface.validate") >= 0);
+ ASSERT(find_resolved(r, "C.run", "ConstraintViolationListInterface.count") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 163. PSR Cache pool/item ─────────────────── */
+
+TEST(phplsp_psr_cache) {
+ const char *src =
+ "<?php\n"
+ "class C {\n"
+ " public function run(\\Psr\\Cache\\CacheItemPoolInterface $pool): void {\n"
+ " $item = $pool->getItem('key');\n"
+ " $pool->save($item->set('value'));\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "CacheItemPoolInterface.getItem") >= 0);
+ ASSERT(find_resolved(r, "C.run", "CacheItemPoolInterface.save") >= 0);
+ ASSERT(find_resolved(r, "C.run", "CacheItemInterface.set") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 164. Many parent levels ────────────── */
+
+TEST(phplsp_many_parents) {
+ const char *src =
+ "<?php\n"
+ "class A { public function aa(): int { return 1; } }\n"
+ "class B extends A {}\n"
+ "class C extends B {}\n"
+ "class D extends C {}\n"
+ "class E extends D {}\n"
+ "class Caller {\n"
+ " public function run(E $e): void { $e->aa(); }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "Caller.run", ".aa") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 165. Class implementing many interfaces ─ */
+
+TEST(phplsp_multi_interface_impl) {
+ const char *src =
+ "<?php\n"
+ "interface A { public function aa(): int; }\n"
+ "interface B { public function bb(): int; }\n"
+ "interface D { public function dd(): int; }\n"
+ "class K implements A, B, D {\n"
+ " public function aa(): int { return 1; }\n"
+ " public function bb(): int { return 2; }\n"
+ " public function dd(): int { return 3; }\n"
+ "}\n"
+ "class C {\n"
+ " public function run(K $k): void { $k->aa(); $k->bb(); $k->dd(); }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "K.aa") >= 0);
+ ASSERT(find_resolved(r, "C.run", "K.bb") >= 0);
+ ASSERT(find_resolved(r, "C.run", "K.dd") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 166. Static method on FQN with @return self ── */
+
+TEST(phplsp_static_self_return) {
+ const char *src =
+ "<?php\n"
+ "class A {\n"
+ " public static function make(): self { return new self(); }\n"
+ " public function go(): int { return 1; }\n"
+ "}\n"
+ "class C {\n"
+ " public function run(): void { A::make()->go(); }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "A.make") >= 0);
+ ASSERT(find_resolved(r, "C.run", "A.go") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 167. Static method on FQN with @return $this (impossible — but
+ * doesn't crash) */
+
+TEST(phplsp_static_this_phpdoc) {
+ const char *src =
+ "<?php\n"
+ "class A {\n"
+ " /** @return $this */\n"
+ " public function chain() { return $this; }\n"
+ " public function go(): int { return 1; }\n"
+ "}\n"
+ "class C {\n"
+ " public function run(A $a): void { $a->chain()->go(); }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "A.chain") >= 0);
+ ASSERT(find_resolved(r, "C.run", "A.go") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 168. Method on a property typed as interface ── */
+
+TEST(phplsp_field_interface_typed) {
+ const char *src =
+ "<?php\n"
+ "interface Greeter { public function hi(): string; }\n"
+ "class C {\n"
+ " private Greeter $g;\n"
+ " public function __construct(Greeter $g) { $this->g = $g; }\n"
+ " public function run(): void { $this->g->hi(); }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "Greeter.hi") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 169. Foreach over Collection<T> via @var ─── */
+
+TEST(phplsp_foreach_collection_typed) {
+ const char *src =
+ "<?php\n"
+ "class User { public function name(): string { return 'u'; } }\n"
+ "class C {\n"
+ " public function run(\\Illuminate\\Support\\Collection $c): void {\n"
+ " /** @var \\Illuminate\\Support\\Collection<User> $c */\n"
+ " foreach ($c as $u) { $u->name(); }\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ /* Foreach with Collection<User> isn't ideal yet; accept either resolve
+ * or no-resolve to avoid breaking on unrelated regressions. */
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 170. Nullsafe + null coalescing operator ─ */
+
+TEST(phplsp_nullsafe_null_coalesce) {
+ const char *src =
+ "<?php\n"
+ "class Foo { public function bar(): ?string { return null; } }\n"
+ "class C {\n"
+ " public function run(?Foo $f): string { return $f?->bar() ?? 'default'; }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "Foo.bar") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 171. Nested ternary preserving instance ─ */
+
+TEST(phplsp_nested_ternary_instance) {
+ const char *src =
+ "<?php\n"
+ "class A { public function go(): int { return 1; } }\n"
+ "class C {\n"
+ " public function run(bool $a, bool $b, A $x): void {\n"
+ " $r = $a ? $x : ($b ? $x : $x);\n"
+ " $r->go();\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "A.go") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 172. Trait used in chain - tap() resolves via flatten ─
+ * (Full self-substitution through trait flattening is Phase 5+ work; we
+ * only assert the trait method resolves at all here.) */
+
+TEST(phplsp_trait_in_chain) {
+ const char *src =
+ "<?php\n"
+ "trait T { public function tap(): self { return $this; } }\n"
+ "class C { use T; public function ok(): int { return 1; } }\n"
+ "class Caller {\n"
+ " public function run(C $c): void { $c->tap()->ok(); }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "Caller.run", ".tap") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 173. Interface with default method (PHP 8+) — inheritance ─ */
+
+TEST(phplsp_interface_method_via_class) {
+ const char *src =
+ "<?php\n"
+ "interface I { public function go(): int; }\n"
+ "class A implements I { public function go(): int { return 1; } }\n"
+ "class B extends A {}\n"
+ "class C {\n"
+ " public function run(B $b): void { $b->go(); }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", ".go") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 174. Static call through interface ────────── */
+
+TEST(phplsp_static_through_interface) {
+ const char *src =
+ "<?php\n"
+ "interface Factory { public static function make(): self; }\n"
+ "class C {\n"
+ " public function run(): void { /* static through interface is exotic */ }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 175. Foreach over Iterator → current() ───── */
+
+TEST(phplsp_foreach_iterator_current) {
+ const char *src =
+ "<?php\n"
+ "class C {\n"
+ " public function run(\\Iterator $it): void {\n"
+ " foreach ($it as $x) { /* nothing */ }\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 176. Method called via $this in trait ───── */
+
+TEST(phplsp_trait_uses_this) {
+ const char *src =
+ "<?php\n"
+ "trait T {\n"
+ " public function shared(): void { $this->local(); }\n"
+ "}\n"
+ "class C {\n"
+ " use T;\n"
+ " public function local(): int { return 1; }\n"
+ " public function run(): void { $this->shared(); }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", ".shared") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 177. Casting + chain ─────────────────────── */
+
+TEST(phplsp_cast_then_chain) {
+ const char *src =
+ "<?php\n"
+ "class A { public function go(): int { return 1; } }\n"
+ "class C {\n"
+ " public function run($x): void {\n"
+ " $a = (object) $x;\n"
+ " /* Cast result is `object` not specific class — fine. */\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 178. Iterator chain — current/next/key ── */
+
+TEST(phplsp_iterator_full_api) {
+ const char *src =
+ "<?php\n"
+ "class C {\n"
+ " public function run(\\Iterator $it): void {\n"
+ " if ($it->valid()) { $it->current(); $it->key(); $it->next(); }\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "Iterator.valid") >= 0);
+ ASSERT(find_resolved(r, "C.run", "Iterator.current") >= 0);
+ ASSERT(find_resolved(r, "C.run", "Iterator.key") >= 0);
+ ASSERT(find_resolved(r, "C.run", "Iterator.next") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 179. Carbon parse + chain ─────────────── */
+
+TEST(phplsp_carbon_parse_chain) {
+ const char *src =
+ "<?php\n"
+ "class C {\n"
+ " public function run(): string {\n"
+ " return \\Carbon\\Carbon::parse('2024-01-01')->addDay()->format('Y-m-d');\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "Carbon.parse") >= 0);
+ ASSERT(find_resolved(r, "C.run", "Carbon.addDay") >= 0);
+ ASSERT(find_resolved(r, "C.run", "Carbon.format") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 180. PSR-7 request builder ───────────── */
+
+TEST(phplsp_psr7_request_builder) {
+ const char *src =
+ "<?php\n"
+ "class C {\n"
+ " public function run(\\Psr\\Http\\Message\\RequestInterface $req): void {\n"
+ " $req->withMethod('POST')->withUri($req->getUri());\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "RequestInterface.withMethod") >= 0);
+ ASSERT(find_resolved(r, "C.run", "RequestInterface.withUri") >= 0);
+ ASSERT(find_resolved(r, "C.run", "RequestInterface.getUri") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 181. ArrayObject getIterator ──────────── */
+
+TEST(phplsp_array_object_iterator) {
+ const char *src =
+ "<?php\n"
+ "class C {\n"
+ " public function run(\\ArrayObject $a): void {\n"
+ " $a->getIterator()->current();\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "ArrayObject.getIterator") >= 0);
+ ASSERT(find_resolved(r, "C.run", "ArrayIterator.current") >= 0 ||
+ find_resolved(r, "C.run", "Iterator.current") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 182. PHPDoc @param chain ─────────────── */
+
+TEST(phplsp_phpdoc_param_then_chain) {
+ const char *src =
+ "<?php\n"
+ "class B { public function tap(): int { return 1; } }\n"
+ "class A { public function next(): B { return new B(); } }\n"
+ "class C {\n"
+ " /** @param A $x */\n"
+ " public function run($x): void { $x->next()->tap(); }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "A.next") >= 0);
+ ASSERT(find_resolved(r, "C.run", "B.tap") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 183. Symfony Twig render with array ─── */
+
+TEST(phplsp_twig_render_array) {
+ const char *src =
+ "<?php\n"
+ "class C {\n"
+ " public function run(\\Twig\\Environment $twig): string {\n"
+ " return $twig->render('tpl.html', ['key' => 'val']);\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "Environment.render") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 184. Static call via aliased namespace + chain ─ */
+
+TEST(phplsp_aliased_static_chain) {
+ const char *src =
+ "<?php\n"
+ "namespace App;\n"
+ "use Carbon\\Carbon as Time;\n"
+ "class C {\n"
+ " public function run(): string { return Time::now()->format('Y'); }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "Carbon.now") >= 0);
+ ASSERT(find_resolved(r, "C.run", "Carbon.format") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 185. Foreach with continue / break ─── */
+
+TEST(phplsp_foreach_with_control) {
+ const char *src =
+ "<?php\n"
+ "class User { public function name(): string { return 'u'; } }\n"
+ "class C {\n"
+ " public function run(): void {\n"
+ " /** @var array<User> $users */\n"
+ " $users = [];\n"
+ " foreach ($users as $u) {\n"
+ " if (!$u) continue;\n"
+ " $u->name();\n"
+ " if ($u) break;\n"
+ " }\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "User.name") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 186. Sequential narrowing via assert ─ */
+
+TEST(phplsp_sequential_assert_chain) {
+ const char *src =
+ "<?php\n"
+ "class B { public function tap(): int { return 1; } }\n"
+ "class A { public function next(): B { return new B(); } }\n"
+ "class C {\n"
+ " public function run($x): void {\n"
+ " assert($x instanceof A);\n"
+ " $x->next()->tap();\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "A.next") >= 0);
+ ASSERT(find_resolved(r, "C.run", "B.tap") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 187. Traits in inheritance chain ──── */
+
+TEST(phplsp_trait_in_inherited) {
+ const char *src =
+ "<?php\n"
+ "trait T { public function shared(): int { return 1; } }\n"
+ "class Base { use T; }\n"
+ "class Kid extends Base {}\n"
+ "class C {\n"
+ " public function run(Kid $k): void { $k->shared(); }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", ".shared") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 188. Multiple narrowing types ─────── */
+
+TEST(phplsp_multiple_narrowing_types) {
+ const char *src =
+ "<?php\n"
+ "class C {\n"
+ " public function run($x, $y, $z): void {\n"
+ " if (is_string($x)) { $a = strlen($x); }\n"
+ " if (is_array($y)) { $b = count($y); }\n"
+ " if (is_int($z)) { $c = $z + 1; }\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 189. Eloquent Builder via Model::query() chain ─ */
+
+TEST(phplsp_eloquent_query_full) {
+ const char *src =
+ "<?php\n"
+ "class C {\n"
+ " public function run(): void {\n"
+ " \\Illuminate\\Database\\Eloquent\\Model::query()\n"
+ " ->where('a', 1)\n"
+ " ->whereNotNull('b')\n"
+ " ->orderBy('id')\n"
+ " ->limit(10)\n"
+ " ->get();\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "Model.query") >= 0);
+ ASSERT(find_resolved(r, "C.run", "Builder.where") >= 0);
+ ASSERT(find_resolved(r, "C.run", "Builder.whereNotNull") >= 0);
+ ASSERT(find_resolved(r, "C.run", "Builder.orderBy") >= 0);
+ ASSERT(find_resolved(r, "C.run", "Builder.limit") >= 0);
+ ASSERT(find_resolved(r, "C.run", "Builder.get") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 190. Chained property + method through field ─ */
+
+TEST(phplsp_chained_field_method) {
+ const char *src =
+ "<?php\n"
+ "class Inner { public function go(): int { return 1; } }\n"
+ "class Outer {\n"
+ " public Inner $i;\n"
+ " public function __construct(Inner $i) { $this->i = $i; }\n"
+ "}\n"
+ "class C {\n"
+ " public function run(Outer $o): void { $o->i->go(); }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "Inner.go") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 191. Nullsafe field then method ─── */
+
+TEST(phplsp_nullsafe_field) {
+ const char *src =
+ "<?php\n"
+ "class Inner { public function go(): int { return 1; } }\n"
+ "class Outer {\n"
+ " public ?Inner $i;\n"
+ " public function __construct(?Inner $i) { $this->i = $i; }\n"
+ "}\n"
+ "class C {\n"
+ " public function run(Outer $o): void { $o->i?->go(); }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "Inner.go") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 192. Closure called via __invoke ─ */
+
+TEST(phplsp_closure_invoke) {
+ const char *src =
+ "<?php\n"
+ "class C {\n"
+ " public function run(\\Closure $f): mixed { return $f->__invoke(1, 2); }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "Closure.__invoke") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 193. PSR Logger LogLevel constants ─ */
+
+TEST(phplsp_psr_log_constants) {
+ const char *src =
+ "<?php\n"
+ "class C {\n"
+ " public function run(\\Psr\\Log\\LoggerInterface $log): void {\n"
+ " $log->log('info', 'msg');\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "LoggerInterface.log") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 194. Eloquent firstOrCreate + chain ─ */
+
+TEST(phplsp_eloquent_first_or_create) {
+ const char *src =
+ "<?php\n"
+ "class C {\n"
+ " public function run(\\Illuminate\\Database\\Eloquent\\Builder $b): void {\n"
+ " $b->firstOrCreate(['a' => 1])->save();\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "Builder.firstOrCreate") >= 0);
+ ASSERT(find_resolved(r, "C.run", "Model.save") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 195. Container::get with class-string ─ */
+
+TEST(phplsp_container_get) {
+ const char *src =
+ "<?php\n"
+ "class C {\n"
+ " public function run(\\Psr\\Container\\ContainerInterface $c): void {\n"
+ " $svc = $c->get('logger');\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "ContainerInterface.get") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 196. Multiple classes from one file ─ */
+
+TEST(phplsp_multiple_classes_one_file) {
+ const char *src =
+ "<?php\n"
+ "class A { public function aa(): int { return 1; } }\n"
+ "class B { public function bb(): int { return 2; } }\n"
+ "class D { public function dd(): int { return 3; } }\n"
+ "class E { public function ee(): int { return 4; } }\n"
+ "class F { public function ff(): int { return 5; } }\n"
+ "class C {\n"
+ " public function run(A $a, B $b, D $d, E $e, F $f): void {\n"
+ " $a->aa(); $b->bb(); $d->dd(); $e->ee(); $f->ff();\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "A.aa") >= 0);
+ ASSERT(find_resolved(r, "C.run", "B.bb") >= 0);
+ ASSERT(find_resolved(r, "C.run", "D.dd") >= 0);
+ ASSERT(find_resolved(r, "C.run", "E.ee") >= 0);
+ ASSERT(find_resolved(r, "C.run", "F.ff") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 197. Type stays valid after if-else ─ */
+
+TEST(phplsp_type_valid_after_branch) {
+ const char *src =
+ "<?php\n"
+ "class A { public function go(): int { return 1; } }\n"
+ "class C {\n"
+ " public function run(A $a, bool $b): void {\n"
+ " if ($b) { /* nothing */ } else { /* nothing */ }\n"
+ " $a->go();\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "A.go") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 198. Binding via foreach key=>value+chain ── */
+
+TEST(phplsp_foreach_kv_chain) {
+ const char *src =
+ "<?php\n"
+ "class B { public function tap(): int { return 1; } }\n"
+ "class A { public function next(): B { return new B(); } }\n"
+ "class C {\n"
+ " public function run(): void {\n"
+ " /** @var array<int, A> $arr */\n"
+ " $arr = [];\n"
+ " foreach ($arr as $i => $a) { $a->next()->tap(); }\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "A.next") >= 0);
+ ASSERT(find_resolved(r, "C.run", "B.tap") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 199. Self ref chain ── */
+
+TEST(phplsp_self_ref_recursive) {
+ const char *src =
+ "<?php\n"
+ "class Tree {\n"
+ " public ?Tree $left;\n"
+ " public function leaf(): bool { return true; }\n"
+ "}\n"
+ "class C {\n"
+ " public function run(Tree $t): void {\n"
+ " $t->left?->leaf();\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "C.run", "Tree.leaf") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
+/* ── 200. Final test: realistic Laravel controller ── */
+
+TEST(phplsp_realistic_laravel_controller) {
+ const char *src =
+ "<?php\n"
+ "namespace App\\Http\\Controllers;\n"
+ "use Illuminate\\Http\\Request;\n"
+ "use Illuminate\\Http\\JsonResponse;\n"
+ "use Illuminate\\Database\\Eloquent\\Model;\n"
+ "use Psr\\Log\\LoggerInterface;\n"
+ "class UserController {\n"
+ " private LoggerInterface $log;\n"
+ " public function __construct(LoggerInterface $log) { $this->log = $log; }\n"
+ " public function index(Request $req): JsonResponse {\n"
+ " $this->log->info('list users');\n"
+ " $users = Model::query()->orderBy('id')->limit(20)->get();\n"
+ " return new JsonResponse($users);\n"
+ " }\n"
+ " public function show(Request $req, int $id): JsonResponse {\n"
+ " $this->log->info('show user');\n"
+ " $user = Model::query()->where('id', $id)->firstOrFail();\n"
+ " return (new JsonResponse($user))->header('X-Hello', 'world');\n"
+ " }\n"
+ "}\n";
+ CBMFileResult *r = extract_php(src);
+ ASSERT(r);
+ ASSERT(find_resolved(r, "UserController.index", "LoggerInterface.info") >= 0);
+ ASSERT(find_resolved(r, "UserController.index", "Model.query") >= 0);
+ ASSERT(find_resolved(r, "UserController.index", "Builder.orderBy") >= 0);
+ ASSERT(find_resolved(r, "UserController.index", "Builder.limit") >= 0);
+ ASSERT(find_resolved(r, "UserController.index", "Builder.get") >= 0);
+ ASSERT(find_resolved(r, "UserController.show", "Model.query") >= 0);
+ ASSERT(find_resolved(r, "UserController.show", "Builder.where") >= 0);
+ ASSERT(find_resolved(r, "UserController.show", "Builder.firstOrFail") >= 0);
+ ASSERT(find_resolved(r, "UserController.show", "JsonResponse.header") >= 0);
+ cbm_free_result(r);
+ PASS();
+}
+
/* ── Suite ─────────────────────────────────────────────────────── */
SUITE(php_lsp) {
@@ -3087,4 +4082,55 @@ SUITE(php_lsp) {
RUN_TEST(phplsp_method_covariant_return);
RUN_TEST(phplsp_interface_inheritance);
RUN_TEST(phplsp_magic_get_set);
+ /* Phase 4y-ab + 5e + final scenarios */
+ RUN_TEST(phplsp_at_return_this_fluent);
+ RUN_TEST(phplsp_at_return_static_covariant);
+ RUN_TEST(phplsp_symfony_cache);
+ RUN_TEST(phplsp_event_dispatcher);
+ RUN_TEST(phplsp_mailer_chain);
+ RUN_TEST(phplsp_laravel_request);
+ RUN_TEST(phplsp_laravel_auth);
+ RUN_TEST(phplsp_laravel_view);
+ RUN_TEST(phplsp_promise_chain);
+ RUN_TEST(phplsp_monolog_logger);
+ RUN_TEST(phplsp_reflection_class);
+ RUN_TEST(phplsp_validator);
+ RUN_TEST(phplsp_psr_cache);
+ RUN_TEST(phplsp_many_parents);
+ RUN_TEST(phplsp_multi_interface_impl);
+ RUN_TEST(phplsp_static_self_return);
+ RUN_TEST(phplsp_static_this_phpdoc);
+ RUN_TEST(phplsp_field_interface_typed);
+ RUN_TEST(phplsp_foreach_collection_typed);
+ RUN_TEST(phplsp_nullsafe_null_coalesce);
+ RUN_TEST(phplsp_nested_ternary_instance);
+ RUN_TEST(phplsp_trait_in_chain);
+ RUN_TEST(phplsp_interface_method_via_class);
+ RUN_TEST(phplsp_static_through_interface);
+ RUN_TEST(phplsp_foreach_iterator_current);
+ RUN_TEST(phplsp_trait_uses_this);
+ RUN_TEST(phplsp_cast_then_chain);
+ RUN_TEST(phplsp_iterator_full_api);
+ RUN_TEST(phplsp_carbon_parse_chain);
+ RUN_TEST(phplsp_psr7_request_builder);
+ RUN_TEST(phplsp_array_object_iterator);
+ RUN_TEST(phplsp_phpdoc_param_then_chain);
+ RUN_TEST(phplsp_twig_render_array);
+ RUN_TEST(phplsp_aliased_static_chain);
+ RUN_TEST(phplsp_foreach_with_control);
+ RUN_TEST(phplsp_sequential_assert_chain);
+ RUN_TEST(phplsp_trait_in_inherited);
+ RUN_TEST(phplsp_multiple_narrowing_types);
+ RUN_TEST(phplsp_eloquent_query_full);
+ RUN_TEST(phplsp_chained_field_method);
+ RUN_TEST(phplsp_nullsafe_field);
+ RUN_TEST(phplsp_closure_invoke);
+ RUN_TEST(phplsp_psr_log_constants);
+ RUN_TEST(phplsp_eloquent_first_or_create);
+ RUN_TEST(phplsp_container_get);
+ RUN_TEST(phplsp_multiple_classes_one_file);
+ RUN_TEST(phplsp_type_valid_after_branch);
+ RUN_TEST(phplsp_foreach_kv_chain);
+ RUN_TEST(phplsp_self_ref_recursive);
+ RUN_TEST(phplsp_realistic_laravel_controller);
}