@@ -52,7 +52,14 @@ public function concretizeMixedUsage(string $className): self
5252 );
5353 }
5454
55- public function serialize (): string
55+ /**
56+ * Scope file is passed to optimize transferred data size (and thus result cache size)
57+ * - PHPStan itself transfers all collector data along with scope file
58+ * - thus if our data match those already-transferred ones, lets omit those
59+ *
60+ * @see https://github.com/phpstan/phpstan-src/blob/2fe4e0f94e75fe8844a21fdb81799f01f0591dfe/src/Analyser/FileAnalyser.php#L198
61+ */
62+ public function serialize (string $ scopeFile ): string
5663 {
5764 $ origin = $ this ->usage ->getOrigin ();
5865 $ memberRef = $ this ->usage ->getMemberRef ();
@@ -63,7 +70,7 @@ public function serialize(): string
6370 'o ' => [
6471 'c ' => $ origin ->getClassName (),
6572 'm ' => $ origin ->getMethodName (),
66- 'f ' => $ origin ->getFile (),
73+ 'f ' => $ origin ->getFile () === $ scopeFile ? ' _ ' : $ origin -> getFile () ,
6774 'l ' => $ origin ->getLine (),
6875 'p ' => $ origin ->getProvider (),
6976 'n ' => $ origin ->getNote (),
@@ -82,7 +89,7 @@ public function serialize(): string
8289 }
8390 }
8491
85- public static function deserialize (string $ data ): self
92+ public static function deserialize (string $ data, string $ scopeFile ): self
8693 {
8794 try {
8895 /** @var array{e: string|null, t: MemberType::*, o: array{c: string|null, m: string|null, f: string|null, l: int|null, p: string|null, n: string|null}, m: array{c: string|null, m: string, d: bool}} $result */
@@ -92,7 +99,14 @@ public static function deserialize(string $data): self
9299 }
93100
94101 $ memberType = $ result ['t ' ];
95- $ origin = new UsageOrigin ($ result ['o ' ]['c ' ], $ result ['o ' ]['m ' ], $ result ['o ' ]['f ' ], $ result ['o ' ]['l ' ], $ result ['o ' ]['p ' ], $ result ['o ' ]['n ' ]);
102+ $ origin = new UsageOrigin (
103+ $ result ['o ' ]['c ' ],
104+ $ result ['o ' ]['m ' ],
105+ $ result ['o ' ]['f ' ] === '_ ' ? $ scopeFile : $ result ['o ' ]['f ' ],
106+ $ result ['o ' ]['l ' ],
107+ $ result ['o ' ]['p ' ],
108+ $ result ['o ' ]['n ' ],
109+ );
96110 $ exclusionReason = $ result ['e ' ];
97111
98112 $ usage = $ memberType === MemberType::CONSTANT
0 commit comments