packages/sql-catalog/src/Core/Catalog/CallSite.php

1<?php
2
3declare(strict_types=1);
4
5namespace SqlCatalog\Core\Catalog;
6
7/**
8 * Where in the analyzed source a statement is issued.
9 *
10 * @visibility root
11 */
12final class CallSite
13{
14    /**
15     * The sink reported for a database call whose receiver could not be identified.
16     */
17    public const UNMATCHED = 'unmatched';
18
19    /**
20     * @param string $file The path the statement was found in, relative to the analysis root
21     * @param int $line The line the call is written on
22     * @param string $function The enclosing function, as `Class::method`, `function` or `{main}`
23     * @param string $sink The identifier of the database call that was matched
24     */
25    public function __construct(
26        public readonly string $file,
27        public readonly int $line,
28        public readonly string $function,
29        public readonly string $sink,
30    ) {
31    }
32
33    /**
34     * The site written the way an editor jumps to it.
35     */
36    public function display(): string
37    {
38        return $this->file . ':' . $this->line;
39    }
40}
41