2222class FunctionSignatureMapProvider implements SignatureMapProvider
2323{
2424
25- /** @var mixed[]|null */
26- private ? array $ signatureMap = null ;
25+ /** @var array<string, mixed[]> */
26+ private static array $ signatureMaps = [] ;
2727
2828/** @var array<string, array{hasSideEffects: bool}>|null */
29- private ?array $ functionMetadata = null ;
29+ private static ?array $ functionMetadata = null ;
3030
3131public function __construct (
3232private SignatureMapParser $ parser ,
@@ -126,7 +126,7 @@ public function hasMethodMetadata(string $className, string $methodName): bool
126126
127127public function hasFunctionMetadata (string $ name ): bool
128128{
129- $ signatureMap = $ this -> getFunctionMetadataMap ();
129+ $ signatureMap = self :: getFunctionMetadataMap ();
130130return array_key_exists (strtolower ($ name ), $ signatureMap );
131131}
132132
@@ -149,94 +149,95 @@ public function getFunctionMetadata(string $functionName): array
149149throw new ShouldNotHappenException ();
150150}
151151
152- return $ this -> getFunctionMetadataMap ()[$ functionName ];
152+ return self :: getFunctionMetadataMap ()[$ functionName ];
153153}
154154
155155/**
156156 * @return array<string, array{hasSideEffects: bool}>
157157 */
158- private function getFunctionMetadataMap (): array
158+ private static function getFunctionMetadataMap (): array
159159{
160- if ($ this -> functionMetadata === null ) {
160+ if (self :: $ functionMetadata === null ) {
161161/** @var array<string, array{hasSideEffects: bool}> $metadata */
162162$ metadata = require __DIR__ . '/../../../resources/functionMetadata.php ' ;
163- $ this -> functionMetadata = array_change_key_case ($ metadata , CASE_LOWER );
163+ self :: $ functionMetadata = array_change_key_case ($ metadata , CASE_LOWER );
164164}
165165
166- return $ this -> functionMetadata ;
166+ return self :: $ functionMetadata ;
167167}
168168
169169/**
170170 * @return mixed[]
171171 */
172172public function getSignatureMap (): array
173173{
174- if ($ this ->signatureMap === null ) {
175- $ signatureMap = require __DIR__ . '/../../../resources/functionMap.php ' ;
176- if (!is_array ($ signatureMap )) {
174+ $ cacheKey = sprintf ('%d-%d ' , $ this ->phpVersion ->getVersionId (), $ this ->stricterFunctionMap ? 1 : 0 );
175+ if (array_key_exists ($ cacheKey , self ::$ signatureMaps )) {
176+ return self ::$ signatureMaps [$ cacheKey ];
177+ }
178+
179+ $ signatureMap = require __DIR__ . '/../../../resources/functionMap.php ' ;
180+ if (!is_array ($ signatureMap )) {
181+ throw new ShouldNotHappenException ('Signature map could not be loaded. ' );
182+ }
183+
184+ $ signatureMap = array_change_key_case ($ signatureMap , CASE_LOWER );
185+
186+ if ($ this ->stricterFunctionMap ) {
187+ $ stricterFunctionMap = require __DIR__ . '/../../../resources/functionMap_bleedingEdge.php ' ;
188+ if (!is_array ($ stricterFunctionMap )) {
177189throw new ShouldNotHappenException ('Signature map could not be loaded. ' );
178190}
179191
180- $ signatureMap = array_change_key_case ($ signatureMap , CASE_LOWER );
192+ $ signatureMap = $ this -> computeSignatureMap ($ signatureMap , $ stricterFunctionMap );
181193
182- if ($ this ->stricterFunctionMap ) {
183- $ stricterFunctionMap = require __DIR__ . '/../../../resources/functionMap_bleedingEdge .php ' ;
184- if (!is_array ($ stricterFunctionMap )) {
194+ if ($ this ->phpVersion -> getVersionId () >= 80000 ) {
195+ $ php80StricterFunctionMapDelta = require __DIR__ . '/../../../resources/functionMap_php80delta_bleedingEdge .php ' ;
196+ if (!is_array ($ php80StricterFunctionMapDelta )) {
185197throw new ShouldNotHappenException ('Signature map could not be loaded. ' );
186198}
187199
188- $ signatureMap = $ this ->computeSignatureMap ($ signatureMap , $ stricterFunctionMap );
189-
190- if ($ this ->phpVersion ->getVersionId () >= 80000 ) {
191- $ php80StricterFunctionMapDelta = require __DIR__ . '/../../../resources/functionMap_php80delta_bleedingEdge.php ' ;
192- if (!is_array ($ php80StricterFunctionMapDelta )) {
193- throw new ShouldNotHappenException ('Signature map could not be loaded. ' );
194- }
195-
196- $ signatureMap = $ this ->computeSignatureMap ($ signatureMap , $ php80StricterFunctionMapDelta );
197- }
200+ $ signatureMap = $ this ->computeSignatureMap ($ signatureMap , $ php80StricterFunctionMapDelta );
198201}
202+ }
199203
200- if ($ this ->phpVersion ->getVersionId () >= 70400 ) {
201- $ php74MapDelta = require __DIR__ . '/../../../resources/functionMap_php74delta.php ' ;
202- if (!is_array ($ php74MapDelta )) {
203- throw new ShouldNotHappenException ('Signature map could not be loaded. ' );
204- }
205-
206- $ signatureMap = $ this ->computeSignatureMap ($ signatureMap , $ php74MapDelta );
204+ if ($ this ->phpVersion ->getVersionId () >= 70400 ) {
205+ $ php74MapDelta = require __DIR__ . '/../../../resources/functionMap_php74delta.php ' ;
206+ if (!is_array ($ php74MapDelta )) {
207+ throw new ShouldNotHappenException ('Signature map could not be loaded. ' );
207208}
208209
209- if ($ this ->phpVersion ->getVersionId () >= 80000 ) {
210- $ php80MapDelta = require __DIR__ . '/../../../resources/functionMap_php80delta.php ' ;
211- if (!is_array ($ php80MapDelta )) {
212- throw new ShouldNotHappenException ('Signature map could not be loaded. ' );
213- }
210+ $ signatureMap = $ this ->computeSignatureMap ($ signatureMap , $ php74MapDelta );
211+ }
214212
215- $ signatureMap = $ this ->computeSignatureMap ($ signatureMap , $ php80MapDelta );
213+ if ($ this ->phpVersion ->getVersionId () >= 80000 ) {
214+ $ php80MapDelta = require __DIR__ . '/../../../resources/functionMap_php80delta.php ' ;
215+ if (!is_array ($ php80MapDelta )) {
216+ throw new ShouldNotHappenException ('Signature map could not be loaded. ' );
216217}
217218
218- if ($ this ->phpVersion ->getVersionId () >= 80100 ) {
219- $ php81MapDelta = require __DIR__ . '/../../../resources/functionMap_php81delta.php ' ;
220- if (!is_array ($ php81MapDelta )) {
221- throw new ShouldNotHappenException ('Signature map could not be loaded. ' );
222- }
219+ $ signatureMap = $ this ->computeSignatureMap ($ signatureMap , $ php80MapDelta );
220+ }
223221
224- $ signatureMap = $ this ->computeSignatureMap ($ signatureMap , $ php81MapDelta );
222+ if ($ this ->phpVersion ->getVersionId () >= 80100 ) {
223+ $ php81MapDelta = require __DIR__ . '/../../../resources/functionMap_php81delta.php ' ;
224+ if (!is_array ($ php81MapDelta )) {
225+ throw new ShouldNotHappenException ('Signature map could not be loaded. ' );
225226}
226227
227- if ($ this ->phpVersion ->getVersionId () >= 80200 ) {
228- $ php82MapDelta = require __DIR__ . '/../../../resources/functionMap_php82delta.php ' ;
229- if (!is_array ($ php82MapDelta )) {
230- throw new ShouldNotHappenException ('Signature map could not be loaded. ' );
231- }
228+ $ signatureMap = $ this ->computeSignatureMap ($ signatureMap , $ php81MapDelta );
229+ }
232230
233- $ signatureMap = $ this ->computeSignatureMap ($ signatureMap , $ php82MapDelta );
231+ if ($ this ->phpVersion ->getVersionId () >= 80200 ) {
232+ $ php82MapDelta = require __DIR__ . '/../../../resources/functionMap_php82delta.php ' ;
233+ if (!is_array ($ php82MapDelta )) {
234+ throw new ShouldNotHappenException ('Signature map could not be loaded. ' );
234235}
235236
236- $ this -> signatureMap = $ signatureMap ;
237+ $ signatureMap = $ this -> computeSignatureMap ( $ signatureMap, $ php82MapDelta ) ;
237238}
238239
239- return $ this -> signatureMap ;
240+ return self :: $ signatureMaps [ $ cacheKey ] = $ signatureMap ;
240241}
241242
242243/**
0 commit comments