feat: Add complete PHP language support with trait handling and property extraction
Addresses PHP traits extracted as classes, missing class properties, skipped constants, and invisible trait usage. Adds classifyClassNode to distinguish traits from classes, fixes property extraction for PHP's property_element AST structure (added 4,366 field nodes), and adds visitNode hook for class constants and trait use declarations (increased trait edges from 636 to 1,514). Also improves Liquid schema name handling and file path reference resolution. Verified against Laravel codebase.
This commit is contained in:
@@ -19,6 +19,9 @@ export const phpExtractor: LanguageExtractor = {
|
||||
bodyField: 'body',
|
||||
paramsField: 'parameters',
|
||||
returnField: 'return_type',
|
||||
classifyClassNode: (node) => {
|
||||
return node.type === 'trait_declaration' ? 'trait' : 'class';
|
||||
},
|
||||
getVisibility: (node) => {
|
||||
for (let i = 0; i < node.childCount; i++) {
|
||||
const child = node.child(i);
|
||||
@@ -38,6 +41,43 @@ export const phpExtractor: LanguageExtractor = {
|
||||
}
|
||||
return false;
|
||||
},
|
||||
visitNode: (node, ctx) => {
|
||||
// Handle class constants: const_declaration inside classes
|
||||
// These are skipped by the main visitor because variableTypes check excludes class-like contexts
|
||||
if (node.type === 'const_declaration') {
|
||||
const constElements = node.namedChildren.filter((c: SyntaxNode) => c.type === 'const_element');
|
||||
for (const elem of constElements) {
|
||||
const nameNode = elem.namedChildren.find((c: SyntaxNode) => c.type === 'name');
|
||||
if (!nameNode) continue;
|
||||
const name = getNodeText(nameNode, ctx.source);
|
||||
ctx.createNode('constant', name, elem, {});
|
||||
}
|
||||
return true; // handled
|
||||
}
|
||||
|
||||
// Handle trait usage: use TraitName, OtherTrait; inside classes
|
||||
// Creates unresolved references that will be resolved to 'implements' edges
|
||||
if (node.type === 'use_declaration') {
|
||||
const names = node.namedChildren.filter((c: SyntaxNode) => c.type === 'name' || c.type === 'qualified_name');
|
||||
const parentId = ctx.nodeStack.length > 0 ? ctx.nodeStack[ctx.nodeStack.length - 1] : undefined;
|
||||
if (parentId) {
|
||||
for (const nameNode of names) {
|
||||
const traitName = getNodeText(nameNode, ctx.source);
|
||||
ctx.addUnresolvedReference({
|
||||
fromNodeId: parentId,
|
||||
referenceName: traitName,
|
||||
referenceKind: 'implements',
|
||||
filePath: ctx.filePath,
|
||||
line: node.startPosition.row + 1,
|
||||
column: node.startPosition.column,
|
||||
});
|
||||
}
|
||||
}
|
||||
return true; // handled
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
extractImport: (node, source) => {
|
||||
const importText = source.substring(node.startIndex, node.endIndex).trim();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user