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