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