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

Function resolveModelCall

src/resolution/frameworks/laravel.ts:512–556  ·  view source on GitHub ↗

* Resolve a Model::method() call

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

Source from the content-addressed store, hash-verified

510 * Resolve a Model::method() call
511 */
512function resolveModelCall(
513 className: string,
514 methodName: string,
515 context: ResolutionContext
516): string | null {
517 // Try app/Models/ first (Laravel 8+)
518 let modelPath = `app/Models/${className}.php`;
519 if (context.fileExists(modelPath)) {
520 const nodes = context.getNodesInFile(modelPath);
521 // Look for the method in this class
522 const methodNode = nodes.find(
523 (n) => n.kind === 'method' && n.name === methodName
524 );
525 if (methodNode) {
526 return methodNode.id;
527 }
528 // Return the class itself if method not found
529 const classNode = nodes.find(
530 (n) => n.kind === 'class' && n.name === className
531 );
532 if (classNode) {
533 return classNode.id;
534 }
535 }
536
537 // Try app/ (Laravel 7 and below)
538 modelPath = `app/${className}.php`;
539 if (context.fileExists(modelPath)) {
540 const nodes = context.getNodesInFile(modelPath);
541 const methodNode = nodes.find(
542 (n) => n.kind === 'method' && n.name === methodName
543 );
544 if (methodNode) {
545 return methodNode.id;
546 }
547 const classNode = nodes.find(
548 (n) => n.kind === 'class' && n.name === className
549 );
550 if (classNode) {
551 return classNode.id;
552 }
553 }
554
555 return null;
556}
557
558/**
559 * 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