1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Collectors;
4:
5: use PhpParser\Node;
6:
7: /**
8: * Implement this next to Collector when the collected data contains filesystem paths.
9: *
10: * The result cache stores paths relative to the install location so that it survives a change of
11: * the project's absolute path prefix - a fresh CI checkout directory, a git worktree. Collected data
12: * is opaque to the cache, so paths inside it can only be rewritten by the collector that produced
13: * it. Without this hook they stay absolute and make the cache non-portable.
14: *
15: * The method is static because the cache only ever holds the collector's class name
16: * (CollectedData::getCollectorType()), never an instance.
17: *
18: * @api
19: * @template-covariant TNodeType of Node
20: * @template TValue
21: * @extends Collector<TNodeType, TValue>
22: */
23: interface CollectorWithPaths extends Collector
24: {
25:
26: /**
27: * Returns the collected data with every filesystem path in it passed through $transformPath.
28: * Called once per collected value when the result cache is saved, and again with the inverse
29: * transformation when it is loaded, so it has to be symmetric.
30: *
31: * @param TValue $data
32: * @param callable(string): string $transformPath
33: * @return TValue
34: */
35: public static function transformCollectedDataPaths($data, callable $transformPath);
36:
37: }
38: