MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / methodOf

Function methodOf

src/resolution/frameworks/codeigniter.ts:189–210  ·  view source on GitHub ↗

A method by name on a class, its own or one it inherits. PHP doesn't mind the case.

(cls: Node, name: string, context: ResolutionContext)

Source from the content-addressed store, hash-verified

187
188/** A method by name on a class, its own or one it inherits. PHP doesn't mind the case. */
189function methodOf(cls: Node, name: string, context: ResolutionContext): Node | null {
190 const lower = name.toLowerCase();
191 const seen = new Set<string>();
192 let level: Node[] = [cls];
193 for (let depth = 0; depth < MAX_ANCESTORS && level.length > 0; depth++) {
194 const next: Node[] = [];
195 for (const type of level) {
196 if (seen.has(type.id)) continue;
197 seen.add(type.id);
198 const prefix = `${type.qualifiedName}::`.toLowerCase();
199 const own = context.getNodesInFile(type.filePath).find(
200 (n) => n.kind === 'method' && n.name.toLowerCase() === lower && n.qualifiedName.toLowerCase().startsWith(prefix)
201 );
202 if (own) return own;
203 for (const parent of context.getSupertypeNodes?.(type.id) ?? []) {
204 if (parent.kind === 'class') next.push(parent);
205 }
206 }
207 level = next;
208 }
209 return null;
210}
211
212/** The method the segment after a controller names, `index` when none does, and the class when a variable does. */
213function handlerIn(cls: Node, segments: readonly string[], at: number, context: ResolutionContext): Node {

Callers 2

handlerInFunction · 0.70
resolveFunction · 0.70

Calls 5

hasMethod · 0.80
getSupertypeNodesMethod · 0.80
pushMethod · 0.80
getNodesInFileMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected