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

Function methodOf

src/resolution/frameworks/codeigniter.ts:191–212  ·  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

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

Callers 2

handlerInFunction · 0.70
resolveFunction · 0.70

Calls 5

nodesNamedLowerFunction · 0.90
hasMethod · 0.80
getSupertypeNodesMethod · 0.80
pushMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected