A method by name on a class, its own or one it inherits. PHP doesn't mind the case.
(cls: Node, name: string, context: ResolutionContext)
| 187 | |
| 188 | /** A method by name on a class, its own or one it inherits. PHP doesn't mind the case. */ |
| 189 | function methodOf(cls: Node, name: string, context: ResolutionContext): Node | null { |
| 190 | const lower = name.toLowerCase(); |
| 191 | const seen = new Set<string>(); |
| 192 | let level: Node[] = [cls]; |
| 193 | for (let depth = 0; depth < MAX_ANCESTORS && level.length > 0; depth++) { |
| 194 | const next: Node[] = []; |
| 195 | for (const type of level) { |
| 196 | if (seen.has(type.id)) continue; |
| 197 | seen.add(type.id); |
| 198 | const prefix = `${type.qualifiedName}::`.toLowerCase(); |
| 199 | const own = context.getNodesInFile(type.filePath).find( |
| 200 | (n) => n.kind === 'method' && n.name.toLowerCase() === lower && n.qualifiedName.toLowerCase().startsWith(prefix) |
| 201 | ); |
| 202 | if (own) return own; |
| 203 | for (const parent of context.getSupertypeNodes?.(type.id) ?? []) { |
| 204 | if (parent.kind === 'class') next.push(parent); |
| 205 | } |
| 206 | } |
| 207 | level = next; |
| 208 | } |
| 209 | return null; |
| 210 | } |
| 211 | |
| 212 | /** The method the segment after a controller names, `index` when none does, and the class when a variable does. */ |
| 213 | function handlerIn(cls: Node, segments: readonly string[], at: number, context: ResolutionContext): Node { |
no test coverage detected