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