Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Extend Phound#5458

Open
rlerdorf wants to merge 6 commits intov6from
phound_extend
Open

Extend Phound#5458
rlerdorf wants to merge 6 commits intov6from
phound_extend

Conversation

@rlerdorf
Copy link
Member

@rlerdorf rlerdorf commented Mar 2, 2026

Extends the PhoundPlugin's SQLite database with two new tables: signatures and parameters
These store function/method signatures, property types, constant types, and parameter details for all user-defined code elements.

This enables external tools to perform instant signature lookups from the Phound database without requiring the Phan daemon to be running.
See #5459 for one such external tool.

Changes

  • signatures table: Stores FQSEN, kind (function/method/property/constant), class FQSEN, name, return/property type, static flag, visibility, file path, line number, and docblock
  • parameters table: Stores FQSEN, parameter index, name, type, variadic/reference/optional flags, and default value representation
  • Indexes: signatures_name (for name-based search) and signatures_class (for class-scoped queries)
  • finalizeProcess() now accepts CodeBase parameter and calls writeSignatures() after relationship flattening
  • Signature data is written using individual prepared statements at finalization time (not bulk inserts, runs once, not performance-critical)

What gets stored

  • All user-defined functions (from getFunctionMap())
  • All user-defined class methods, properties, and constants
  • Skips isPHPInternal() elements
  • Skips inherited elements (where getDefiningFQSEN() class differs from current class)

Example queries

-- Find a method signature
SELECT * FROM signatures WHERE fqsen = '\Phan\CodeBase::getMethodByFQSEN';

-- Get parameters for a function
SELECT * FROM parameters WHERE fqsen = '\Phan\CodeBase::getMethodByFQSEN' ORDER BY idx;

-- Search for symbols by name
SELECT fqsen, kind, filepath, lineno FROM signatures WHERE name LIKE '%UnionType%';

-- List all symbols in a file
SELECT fqsen, kind, visibility, lineno FROM signatures WHERE filepath = 'src/Phan/CodeBase.php' ORDER BY lineno;

-- Find potentially unused methods (no callsites)
SELECT s.fqsen, s.filepath, s.lineno
FROM signatures s
LEFT JOIN callsites c ON s.fqsen = c.element AND c.type = 'method'
WHERE c.element IS NULL AND s.kind = 'method'
ORDER BY s.filepath, s.lineno;

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1870aa6289

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Extends the internal PhoundPlugin SQLite output to include symbol signature metadata (signatures + parameter details) so external tools can do offline/instant lookups without requiring the Phan daemon.

Changes:

  • Adds signatures and parameters tables (plus indexes) to the Phound SQLite schema.
  • Updates finalization to accept CodeBase and writes signature/parameter rows at finalization time.
  • Inserts user-defined function/method/property/constant signature data (skipping PHP-internal elements).

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment on lines +856 to +862
if (!self::$db->exec('CREATE INDEX signatures_name ON signatures (name)')) {
throw new Exception("Failed to create index signatures_name");
}
if (!self::$db->exec('CREATE INDEX signatures_class ON signatures (class_fqsen)')) {
throw new Exception("Failed to create index signatures_class");
}
if (!self::$db->exec('CREATE INDEX signatures_filepath ON signatures (filepath)')) {
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finalizeProcess() creates the signatures_* indexes unconditionally. In daemon mode (or any scenario where finalizeProcess() runs more than once in the same PHP process) the static DB handle is reused without dropping tables, so these CREATE INDEX statements will fail with "index already exists" and abort the request. Use CREATE INDEX IF NOT EXISTS ..., or move index creation to the same place tables are (re)created/dropped so it only runs once per DB rebuild.

Suggested change
if (!self::$db->exec('CREATE INDEX signatures_name ON signatures (name)')) {
throw new Exception("Failed to create index signatures_name");
}
if (!self::$db->exec('CREATE INDEX signatures_class ON signatures (class_fqsen)')) {
throw new Exception("Failed to create index signatures_class");
}
if (!self::$db->exec('CREATE INDEX signatures_filepath ON signatures (filepath)')) {
if (!self::$db->exec('CREATE INDEX IF NOT EXISTS signatures_name ON signatures (name)')) {
throw new Exception("Failed to create index signatures_name");
}
if (!self::$db->exec('CREATE INDEX IF NOT EXISTS signatures_class ON signatures (class_fqsen)')) {
throw new Exception("Failed to create index signatures_class");
}
if (!self::$db->exec('CREATE INDEX IF NOT EXISTS signatures_filepath ON signatures (filepath)')) {

Copilot uses AI. Check for mistakes.
Comment on lines +867 to +870
/**
* Write function/method signatures and parameters to the database.
* Includes inherited/trait members so FQSENs for user-defined elements in callsites generally have a matching signature row.
* @throws Exception
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description says inherited elements are skipped (based on getDefiningFQSEN()), but writeSignatures() is documented/implemented to include inherited/trait-provided members via get*MapByFullyQualifiedClassName(). Please reconcile this (update the PR description or change writeSignatures() to match the described behavior).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants