A method by name on a class, its own or an inherited one.
(cls: Node, name: string, context: ResolutionContext)
| 663 | |
| 664 | /** A method by name on a class, its own or an inherited one. */ |
| 665 | function methodOf(cls: Node, name: string, context: ResolutionContext): Node | undefined { |
| 666 | const seen = new Set<string>(); |
| 667 | let level: Node[] = [cls]; |
| 668 | for (let depth = 0; depth < 6 && level.length > 0; depth++) { |
| 669 | const next: Node[] = []; |
| 670 | for (const type of level) { |
| 671 | if (seen.has(type.id)) continue; |
| 672 | seen.add(type.id); |
| 673 | const own = context.getNodesInFile(type.filePath).find( |
| 674 | (n) => n.kind === 'method' && n.name === name && n.qualifiedName.startsWith(`${type.qualifiedName}::`) |
| 675 | ); |
| 676 | if (own) return own; |
| 677 | next.push(...(context.getSupertypeNodes?.(type.id) ?? [])); |
| 678 | } |
| 679 | level = next; |
| 680 | } |
| 681 | return undefined; |
| 682 | } |
| 683 | |
| 684 | /** The service the `\Drupal::service('x')->method()` on this reference's line asks for. */ |
| 685 | function serviceOnLine(ref: UnresolvedRef, method: string, context: ResolutionContext): string | null { |
no test coverage detected