PHP: `extends` with a fully qualified name or an aliased import is resolved by short name — wrong or missing INHERITS edge

未關閉
#3,124 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
58/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
php
領域
backend, devtools

研究方向

Start by locating the PHP inheritance edge resolver and its tests; the issue does not name their paths. Compare how it resolves imported names and fully qualified names against the eight-file reproduction in the issue. Done means all listed INHERITS edges point to the expected parent, including aliased imports and duplicate short names.

由索引模型根據 Issue 內容生成。

描述

bug parsing/quality ux/behavior
Version

codebase-memory-mcp 0.12.1

Platform

Linux (x64)

Install channel

GitHub release archive / install.sh

Binary variant

ui

What happened, and what did you expect?

For a PHP class, the INHERITS edge is resolved by the short name of the parent, not by the name the extends clause gives. Two things follow:

  • extends \Fully\Qualified\Name links to the wrong class when another class with the same short name exists in the child's own namespace. When that other class is the child itself, no edge is written.
  • extends Alias, with use Some\Class as Alias, writes no edge at all, also when the target is unique.

Expected: the edge goes to the class the fully qualified name or the alias names.

This pattern is common where one package overrides a controller of another package and keeps its class name (TYPO3 extensions, Symfony bundles). A query for all subclasses of a base class then misses the overriding classes, or follows a wrong edge.

Reproduction
  1. Code, a dummy project of eight files:
<?php // src/Base.php
namespace Acme\Shop;
class Base { public function run(): void {} }
<?php // src/Model/Imported.php
namespace Acme\Shop\Model;
use Acme\Shop\Base;
class Imported extends Base {}
<?php // src/Model/Qualified.php
namespace Acme\Shop\Model;
class Qualified extends \Acme\Shop\Base {}
<?php // src/Controller/NewController.php
namespace Acme\Shop\Controller;
class NewController extends \Acme\Shop\Base {}
<?php // portal/Controller/NewController.php
namespace Acme\Portal\Controller;
class NewController extends \Acme\Shop\Controller\NewController {}
<?php // portal/Controller/ListController.php
namespace Acme\Portal\Controller;
class ListController extends \Acme\Shop\Controller\NewController {}
<?php // portal/Controller/EditController.php
namespace Acme\Portal\Controller;
use Acme\Shop\Controller\NewController as ShopNewController;
class EditController extends ShopNewController {}
<?php // portal/Controller/AliasController.php
namespace Acme\Portal\Controller;
use Acme\Shop\Base as ShopBase;
class AliasController extends ShopBase {}

composer.json: {"name": "acme/shop", "autoload": {"psr-4": {"Acme\\Shop\\": "src/", "Acme\\Portal\\": "portal/"}}}

  1. MCP tool calls:
index_repository {"repo_path": "/tmp/repro-php", "mode": "full"}
query_graph {"project": "tmp-repro-php", "format": "json",
  "query": "MATCH (a:Class)-[r:INHERITS]->(b) RETURN a.name, a.file_path, b.name, b.file_path"}
  1. Result against expectation:
Child extends Expected parent Actual
src/Model/Imported.php Base (imported) src/Base.php correct
src/Model/Qualified.php \Acme\Shop\Base src/Base.php correct
src/Controller/NewController.php \Acme\Shop\Base src/Base.php correct
portal/Controller/ListController.php \Acme\Shop\Controller\NewController src/Controller/NewController.php edge to portal/Controller/NewController.php (wrong class)
portal/Controller/NewController.php \Acme\Shop\Controller\NewController src/Controller/NewController.php no edge
portal/Controller/EditController.php ShopNewController (alias) src/Controller/NewController.php no edge
portal/Controller/AliasController.php ShopBase (alias) src/Base.php no edge

The index reported no gaps: not_indexed_files_count 0, parse_partial_count 0.

My reading, not verified in the source: the resolver takes the last segment of the name and prefers the child's namespace, and it does not map use … as aliases for extends. #2923 describes a similar short-name fallback for Rust.

Project scale (if relevant)

32 nodes / 42 edges / 9 files

Confirmations
  • I searched existing issues and this is not a duplicate.
  • My reproduction uses shareable code (a dummy snippet or a public OSS repository), not proprietary code.
主要語言
C
星號
45.8k
分支
3.8k
平均合併
2 天 18 小時
30 天內合併 PR
108

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

DeusData/codebase-memory-mcp 的其他 Issue

查看 DeusData/codebase-memory-mcp 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。