`#[Hook('x')]` on a method, or on a class, where it names the method or means `__invoke`.
(filePath: string, content: string, declarations: readonly AttributedDeclaration[])
| 525 | |
| 526 | /** `#[Hook('x')]` on a method, or on a class, where it names the method or means `__invoke`. */ |
| 527 | function oopHookReferences(filePath: string, content: string, declarations: readonly AttributedDeclaration[]): UnresolvedRef[] { |
| 528 | const references: UnresolvedRef[] = []; |
| 529 | const emit = (hook: string, method: string, line: number): void => { |
| 530 | references.push({ |
| 531 | fromNodeId: generateNodeId(filePath, 'method', method, line), |
| 532 | referenceName: `hook_${hook}`, |
| 533 | referenceKind: 'references', |
| 534 | line, |
| 535 | column: 0, |
| 536 | filePath, |
| 537 | language: 'php', |
| 538 | }); |
| 539 | }; |
| 540 | const lineOf = makeLineAt(content, 1); |
| 541 | for (const decl of declarations) { |
| 542 | for (const attribute of decl.attributes) { |
| 543 | if (attribute.name !== 'Hook') continue; |
| 544 | const hook = firstArgument(attribute.args, 'hook'); |
| 545 | if (!hook) continue; |
| 546 | if (decl.method) { |
| 547 | emit(hook, decl.method, decl.line); |
| 548 | continue; |
| 549 | } |
| 550 | const method = /\bmethod\s*:\s*['"](\w+)['"]/.exec(attribute.args)?.[1] ?? '__invoke'; |
| 551 | const at = new RegExp(`\\bfunction\\s+&?\\s*${method}\\s*\\(`).exec(content.slice(decl.offset)); |
| 552 | if (!at) continue; |
| 553 | const offset = decl.offset + at.index; |
| 554 | const marked = declarations.find((other) => other.method === method && other.offset <= offset && offset - other.offset < 200); |
| 555 | emit(hook, method, marked?.line ?? lineOf(offset)); |
| 556 | } |
| 557 | } |
| 558 | return references; |
| 559 | } |
| 560 | |
| 561 | /** A class's plugin definitions: its attributes and its docblock's annotations, each with an `id`. */ |
| 562 | function pluginDefinitions(content: string, declarations: readonly AttributedDeclaration[]): { type: string; id: string; className: string; line: number }[] { |
no test coverage detected