* Resolve a Model::method() call
( className: string, methodName: string, context: ResolutionContext )
| 510 | * Resolve a Model::method() call |
| 511 | */ |
| 512 | function 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 |
no test coverage detected