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

Function resolveModelCall

src/resolution/frameworks/laravel.ts:571–615  ·  view source on GitHub ↗

* Resolve a Model::method() call

(
  className: string,
  methodName: string,
  context: ResolutionContext
)

Source from the content-addressed store, hash-verified

569 * Resolve a Model::method() call
570 */
571function resolveModelCall(
572 className: string,
573 methodName: string,
574 context: ResolutionContext
575): string | null {
576 // Try app/Models/ first (Laravel 8+)
577 let modelPath = `app/Models/${className}.php`;
578 if (context.fileExists(modelPath)) {
579 const nodes = context.getNodesInFile(modelPath);
580 // Look for the method in this class
581 const methodNode = nodes.find(
582 (n) => n.kind === 'method' && n.name === methodName
583 );
584 if (methodNode) {
585 return methodNode.id;
586 }
587 // Return the class itself if method not found
588 const classNode = nodes.find(
589 (n) => n.kind === 'class' && n.name === className
590 );
591 if (classNode) {
592 return classNode.id;
593 }
594 }
595
596 // Try app/ (Laravel 7 and below)
597 modelPath = `app/${className}.php`;
598 if (context.fileExists(modelPath)) {
599 const nodes = context.getNodesInFile(modelPath);
600 const methodNode = nodes.find(
601 (n) => n.kind === 'method' && n.name === methodName
602 );
603 if (methodNode) {
604 return methodNode.id;
605 }
606 const classNode = nodes.find(
607 (n) => n.kind === 'class' && n.name === className
608 );
609 if (classNode) {
610 return classNode.id;
611 }
612 }
613
614 return null;
615}
616
617/**
618 * A route's `Controller@action`: a class name, or a namespace path under the

Callers 1

resolveFunction · 0.85

Calls 2

fileExistsMethod · 0.80
getNodesInFileMethod · 0.65

Tested by

no test coverage detected