-
-
Notifications
You must be signed in to change notification settings - Fork 76
/
Reflector.php
300 lines (270 loc) · 7.73 KB
/
Reflector.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<?php
/** @noinspection ClassConstantCanBeUsedInspection */
declare(strict_types=1);
/*
* This file is part of the humbug/php-scoper package.
*
* Copyright (c) 2017 Théo FIDRY <theo.fidry@gmail.com>,
* Pádraic Brady <padraic.brady@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Humbug\PhpScoper\Symbol;
use JetBrains\PHPStormStub\PhpStormStubsMap;
use function array_keys;
use function array_merge;
/**
* @private
*/
final readonly class Reflector
{
private const MISSING_CLASSES = [
// https://youtrack.jetbrains.com/issue/WI-29503
'MongoInsertBatch',
'MongoDeleteBatch',
];
private const MISSING_FUNCTIONS = [
// https://youtrack.jetbrains.com/issue/WI-53323
'tideways_xhprof_enable',
'tideways_xhprof_disable',
// https://youtrack.jetbrains.com/issue/WI-29503
'bson_encode',
'bson_decode',
// https://youtrack.jetbrains.com/issue/WI-74920
'swoole_async_dns_lookup',
'swoole_async_readfile',
'swoole_async_write',
'swoole_async_writefile',
// https://youtrack.jetbrains.com/issue/WI-74922
'ssdeep_fuzzy_compare',
'ssdeep_fuzzy_hash',
'ssdeep_fuzzy_hash_filename',
// https://youtrack.jetbrains.com/issue/WI-74918
'ps_add_bookmark',
'ps_add_launchlink',
'ps_add_locallink',
'ps_add_note',
'ps_add_pdflink',
'ps_add_weblink',
'ps_arc',
'ps_arcn',
'ps_begin_page',
'ps_begin_pattern',
'ps_begin_template',
'ps_circle',
'ps_clip',
'ps_close_image',
'ps_close',
'ps_closepath_stroke',
'ps_closepath',
'ps_continue_text',
'ps_curveto',
'ps_delete',
'ps_end_page',
'ps_end_pattern',
'ps_end_template',
'ps_fill_stroke',
'ps_fill',
'ps_findfont',
'ps_get_buffer',
'ps_get_parameter',
'ps_get_value',
'ps_hyphenate',
'ps_include_file',
'ps_lineto',
'ps_makespotcolor',
'ps_moveto',
'ps_new',
'ps_open_file',
'ps_open_image_file',
'ps_open_image',
'ps_open_memory_image',
'ps_place_image',
'ps_rect',
'ps_restore',
'ps_rotate',
'ps_save',
'ps_scale',
'ps_set_border_color',
'ps_set_border_dash',
'ps_set_border_style',
'ps_set_info',
'ps_set_parameter',
'ps_set_text_pos',
'ps_set_value',
'ps_setcolor',
'ps_setdash',
'ps_setflat',
'ps_setfont',
'ps_setgray',
'ps_setlinecap',
'ps_setlinejoin',
'ps_setlinewidth',
'ps_setmiterlimit',
'ps_setoverprintmode',
'ps_setpolydash',
'ps_shading_pattern',
'ps_shading',
'ps_shfill',
'ps_show_boxed',
'ps_show_xy2',
'ps_show_xy',
'ps_show2',
'ps_show',
'ps_string_geometry',
'ps_stringwidth',
'ps_stroke',
'ps_symbol_name',
'ps_symbol_width',
'ps_symbol',
'ps_translate',
// https://youtrack.jetbrains.com/issue/WI-74919
'yaz_addinfo',
'yaz_ccl_conf',
'yaz_ccl_parse',
'yaz_close',
'yaz_connect',
'yaz_database',
'yaz_element',
'yaz_errno',
'yaz_error',
'yaz_es_result',
'yaz_es',
'yaz_get_option',
'yaz_hits',
'yaz_itemorder',
'yaz_present',
'yaz_range',
'yaz_record',
'yaz_scan_result',
'yaz_scan',
'yaz_schema',
'yaz_search',
'yaz_set_option',
'yaz_sort',
'yaz_syntax',
'yaz_wait',
// https://youtrack.jetbrains.com/issue/WI-74923
'setproctitle',
'setthreadtitle',
// https://youtrack.jetbrains.com/issue/WI-74927
'mysql_drop_db',
'mysql_create_db',
// https://youtrack.jetbrains.com/issue/WI-74928
'event_base_reinit',
'event_priority_set',
// https://youtrack.jetbrains.com/issue/WI-74965
'uv_get_addrinfo',
'uv_is_writeable',
'ares_ghostbyname',
'uv_async_asend',
'uv_signal_init',
'uv_signal_start',
// PHP 8.3
'ldap_connect_wallet',
'posix_pathconf',
'posix_fpathconf',
// Removed in https://github.com/JetBrains/phpstorm-stubs/pull/1627
'ares_gethostbyname',
'uv_ares_init_options',
'uv_handle_type',
'uv_read2_start',
];
/**
* Basically mirrors https://github.com/nikic/PHP-Parser/blob/9aebf377fcdf205b2156cb78c0bd6e7b2003f106/lib/PhpParser/Lexer.php#L430.
*/
private const MISSING_CONSTANTS = [
// https://github.com/humbug/php-scoper/issues/618
'TRUE',
'FALSE',
'NULL',
// https://youtrack.jetbrains.com/issue/WI-53323
'TIDEWAYS_XHPROF_FLAGS_MEMORY',
'TIDEWAYS_XHPROF_FLAGS_MEMORY_MU',
'TIDEWAYS_XHPROF_FLAGS_MEMORY_PMU',
'TIDEWAYS_XHPROF_FLAGS_CPU',
'TIDEWAYS_XHPROF_FLAGS_NO_BUILTINS',
'TIDEWAYS_XHPROF_FLAGS_MEMORY_ALLOC',
'TIDEWAYS_XHPROF_FLAGS_MEMORY_ALLOC_AS_MU',
// https://youtrack.jetbrains.com/issue/WI-74918/Missing-PostScript-extension-symbols
'ps_LINECAP_BUTT',
'ps_LINECAP_ROUND',
'ps_LINECAP_SQUARED',
'ps_LINEJOIN_MITER',
'ps_LINEJOIN_ROUND',
'ps_LINEJOIN_BEVEL',
];
public static function createWithPhpStormStubs(): self
{
return new self(
self::createSymbolList(
array_keys(PhpStormStubsMap::CLASSES),
self::MISSING_CLASSES,
),
self::createSymbolList(
array_keys(PhpStormStubsMap::FUNCTIONS),
self::MISSING_FUNCTIONS,
),
self::createConstantSymbolList(
array_keys(PhpStormStubsMap::CONSTANTS),
self::MISSING_CONSTANTS,
),
);
}
public static function createEmpty(): self
{
return new self(
SymbolRegistry::create(),
SymbolRegistry::create(),
SymbolRegistry::createForConstants(),
);
}
private function __construct(
private SymbolRegistry $classes,
private SymbolRegistry $functions,
private SymbolRegistry $constants,
) {
}
public function withAdditionalSymbols(
SymbolRegistry $classNames,
SymbolRegistry $functionNames,
SymbolRegistry $constantNames
): self {
return new self(
$this->classes->merge($classNames),
$this->functions->merge($functionNames),
$this->constants->merge($constantNames),
);
}
public function isClassInternal(string $name): bool
{
return $this->classes->matches($name);
}
public function isFunctionInternal(string $name): bool
{
return $this->functions->matches($name);
}
public function isConstantInternal(string $name): bool
{
return $this->constants->matches($name);
}
/**
* @param string[] $sources
*/
private static function createSymbolList(array ...$sources): SymbolRegistry
{
return SymbolRegistry::create(
array_merge(...$sources),
);
}
/**
* @param string[] $sources
*/
private static function createConstantSymbolList(array ...$sources): SymbolRegistry
{
return SymbolRegistry::createForConstants(
array_merge(...$sources),
);
}
}