22
22
class FunctionSignatureMapProvider implements SignatureMapProvider
23
23
{
24
24
25
- /** @var mixed[]|null */
26
- private ? array $ signatureMap = null ;
25
+ /** @var array<string, mixed[]> */
26
+ private static array $ signatureMaps = [] ;
27
27
28
28
/** @var array<string, array{hasSideEffects: bool}>|null */
29
- private ?array $ functionMetadata = null ;
29
+ private static ?array $ functionMetadata = null ;
30
30
31
31
public function __construct (
32
32
private SignatureMapParser $ parser ,
@@ -126,7 +126,7 @@ public function hasMethodMetadata(string $className, string $methodName): bool
126
126
127
127
public function hasFunctionMetadata (string $ name ): bool
128
128
{
129
- $ signatureMap = $ this -> getFunctionMetadataMap ();
129
+ $ signatureMap = self :: getFunctionMetadataMap ();
130
130
return array_key_exists (strtolower ($ name ), $ signatureMap );
131
131
}
132
132
@@ -149,94 +149,95 @@ public function getFunctionMetadata(string $functionName): array
149
149
throw new ShouldNotHappenException ();
150
150
}
151
151
152
- return $ this -> getFunctionMetadataMap ()[$ functionName ];
152
+ return self :: getFunctionMetadataMap ()[$ functionName ];
153
153
}
154
154
155
155
/**
156
156
* @return array<string, array{hasSideEffects: bool}>
157
157
*/
158
- private function getFunctionMetadataMap (): array
158
+ private static function getFunctionMetadataMap (): array
159
159
{
160
- if ($ this -> functionMetadata === null ) {
160
+ if (self :: $ functionMetadata === null ) {
161
161
/** @var array<string, array{hasSideEffects: bool}> $metadata */
162
162
$ 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 );
164
164
}
165
165
166
- return $ this -> functionMetadata ;
166
+ return self :: $ functionMetadata ;
167
167
}
168
168
169
169
/**
170
170
* @return mixed[]
171
171
*/
172
172
public function getSignatureMap (): array
173
173
{
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 )) {
177
189
throw new ShouldNotHappenException ('Signature map could not be loaded. ' );
178
190
}
179
191
180
- $ signatureMap = array_change_key_case ($ signatureMap , CASE_LOWER );
192
+ $ signatureMap = $ this -> computeSignatureMap ($ signatureMap , $ stricterFunctionMap );
181
193
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 )) {
185
197
throw new ShouldNotHappenException ('Signature map could not be loaded. ' );
186
198
}
187
199
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 );
198
201
}
202
+ }
199
203
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. ' );
207
208
}
208
209
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
+ }
214
212
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. ' );
216
217
}
217
218
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
+ }
223
221
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. ' );
225
226
}
226
227
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
+ }
232
230
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. ' );
234
235
}
235
236
236
- $ this -> signatureMap = $ signatureMap ;
237
+ $ signatureMap = $ this -> computeSignatureMap ( $ signatureMap, $ php82MapDelta ) ;
237
238
}
238
239
239
- return $ this -> signatureMap ;
240
+ return self :: $ signatureMaps [ $ cacheKey ] = $ signatureMap ;
240
241
}
241
242
242
243
/**
0 commit comments