Skip to content

Commit 2216e25

Browse files
authored
Update Reflector to account for missing symbols (#333)
1 parent 3199cb1 commit 2216e25

File tree

1 file changed

+261
-10
lines changed

1 file changed

+261
-10
lines changed

src/Reflector.php

Lines changed: 261 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
namespace Humbug\PhpScoper;
1616

1717
use Roave\BetterReflection\SourceLocator\SourceStubber\PhpStormStubsMap;
18-
use function array_key_exists;
18+
use function array_fill_keys;
19+
use function array_keys;
20+
use function array_merge;
1921

2022
/**
2123
* TODO: check if the stubs map could be generated by jetbrains directly instead of being done in BetterReflection
@@ -25,30 +27,279 @@
2527
*/
2628
final class Reflector
2729
{
30+
private const MISSING_CLASSES = [
31+
// https://github.com/JetBrains/phpstorm-stubs/pull/600
32+
'UV',
33+
34+
// https://github.com/JetBrains/phpstorm-stubs/pull/596
35+
'Crypto\Cipher',
36+
'Crypto\CipherException',
37+
'Crypto\Hash',
38+
'Crypto\HashException',
39+
'Crypto\MAC',
40+
'Crypto\MACException',
41+
'Crypto\HMAC',
42+
'Crypto\CMAC',
43+
'Crypto\KDF',
44+
'Crypto\KDFException',
45+
'Crypto\PBKDF2',
46+
'Crypto\PBKDF2Exception',
47+
'Crypto\Base64',
48+
'Crypto\Base64Exception',
49+
'Crypto\Rand',
50+
'Crypto\RandException',
51+
52+
// https://github.com/JetBrains/phpstorm-stubs/pull/594
53+
'parallel\Channel',
54+
'parallel\Channel\Error',
55+
'parallel\Channel\Error\Closed',
56+
'parallel\Channel\Error\Existence',
57+
'parallel\Channel\Error\IllegalValue',
58+
'parallel\Error',
59+
'parallel\Events',
60+
'parallel\Events\Error',
61+
'parallel\Events\Error\Existence',
62+
'parallel\Events\Error\Timeout',
63+
'parallel\Events\Event',
64+
'parallel\Events\Event\Type',
65+
'parallel\Events\Input',
66+
'parallel\Events\Input\Error',
67+
'parallel\Events\Input\Error\Existence',
68+
'parallel\Events\Input\Error\IllegalValue',
69+
'parallel\Future',
70+
'parallel\Future\Error',
71+
'parallel\Future\Error\Cancelled',
72+
'parallel\Future\Error\Foreign',
73+
'parallel\Future\Error\Killed',
74+
'parallel\Runtime',
75+
'parallel\Runtime\Bootstrap',
76+
'parallel\Runtime\Error',
77+
'parallel\Runtime\Error\Bootstrap',
78+
'parallel\Runtime\Error\Closed',
79+
'parallel\Runtime\Error\IllegalFunction',
80+
'parallel\Runtime\Error\IllegalInstruction',
81+
'parallel\Runtime\Error\IllegalParameter',
82+
'parallel\Runtime\Error\IllegalReturn',
83+
];
84+
85+
private const MISSING_FUNCTIONS = [
86+
// https://github.com/JetBrains/phpstorm-stubs/pull/613
87+
'sapi_windows_vt100_support',
88+
89+
// https://github.com/JetBrains/phpstorm-stubs/pull/600
90+
'uv_unref',
91+
'uv_last_error',
92+
'uv_err_name',
93+
'uv_strerror',
94+
'uv_update_time',
95+
'uv_ref',
96+
'uv_run',
97+
'uv_run_once',
98+
'uv_loop_delete',
99+
'uv_now',
100+
'uv_tcp_bind',
101+
'uv_tcp_bind6',
102+
'uv_write',
103+
'uv_write2',
104+
'uv_tcp_nodelay',
105+
'uv_accept',
106+
'uv_shutdown',
107+
'uv_close',
108+
'uv_read_start',
109+
'uv_read2_start',
110+
'uv_read_stop',
111+
'uv_ip4_addr',
112+
'uv_ip6_addr',
113+
'uv_listen',
114+
'uv_tcp_connect',
115+
'uv_tcp_connect6',
116+
'uv_timer_init',
117+
'uv_timer_start',
118+
'uv_timer_stop',
119+
'uv_timer_again',
120+
'uv_timer_set_repeat',
121+
'uv_timer_get_repeat',
122+
'uv_idle_init',
123+
'uv_idle_start',
124+
'uv_idle_stop',
125+
'uv_getaddrinfo',
126+
'uv_tcp_init',
127+
'uv_default_loop',
128+
'uv_loop_new',
129+
'uv_udp_init',
130+
'uv_udp_bind',
131+
'uv_udp_bind6',
132+
'uv_udp_recv_start',
133+
'uv_udp_recv_stop',
134+
'uv_udp_set_membership',
135+
'uv_udp_set_multicast_loop',
136+
'uv_udp_set_multicast_ttl',
137+
'uv_udp_set_broadcast',
138+
'uv_udp_send',
139+
'uv_udp_send6',
140+
'uv_is_active',
141+
'uv_is_readable',
142+
'uv_is_writable',
143+
'uv_walk',
144+
'uv_guess_handle',
145+
'uv_handle_type',
146+
'uv_pipe_init',
147+
'uv_pipe_open',
148+
'uv_pipe_bind',
149+
'uv_pipe_connect',
150+
'uv_pipe_pending_instances',
151+
'uv_ares_init_options',
152+
'ares_gethostbyname',
153+
'uv_loadavg',
154+
'uv_uptime',
155+
'uv_get_free_memory',
156+
'uv_get_total_memory',
157+
'uv_hrtime',
158+
'uv_exepath',
159+
'uv_cpu_info',
160+
'uv_interface_addresses',
161+
'uv_stdio_new',
162+
'uv_spawn',
163+
'uv_process_kill',
164+
'uv_kill',
165+
'uv_chdir',
166+
'uv_rwlock_init',
167+
'uv_rwlock_rdlock',
168+
'uv_rwlock_tryrdlock',
169+
'uv_rwlock_rdunlock',
170+
'uv_rwlock_wrlock',
171+
'uv_rwlock_trywrlock',
172+
'uv_rwlock_wrunlock',
173+
'uv_mutex_init',
174+
'uv_mutex_lock',
175+
'uv_mutex_trylock',
176+
'uv_sem_init',
177+
'uv_sem_post',
178+
'uv_sem_wait',
179+
'uv_sem_trywait',
180+
'uv_prepare_init',
181+
'uv_prepare_start',
182+
'uv_prepare_stop',
183+
'uv_check_init',
184+
'uv_check_start',
185+
'uv_check_stop',
186+
'uv_async_init',
187+
'uv_async_send',
188+
'uv_queue_work',
189+
'uv_fs_open',
190+
'uv_fs_read',
191+
'uv_fs_close',
192+
'uv_fs_write',
193+
'uv_fs_fsync',
194+
'uv_fs_fdatasync',
195+
'uv_fs_ftruncate',
196+
'uv_fs_mkdir',
197+
'uv_fs_rmdir',
198+
'uv_fs_unlink',
199+
'uv_fs_rename',
200+
'uv_fs_utime',
201+
'uv_fs_futime',
202+
'uv_fs_chmod',
203+
'uv_fs_fchmod',
204+
'uv_fs_chown',
205+
'uv_fs_fchown',
206+
'uv_fs_link',
207+
'uv_fs_symlink',
208+
'uv_fs_readlink',
209+
'uv_fs_stat',
210+
'uv_fs_lstat',
211+
'uv_fs_fstat',
212+
'uv_fs_readdir',
213+
'uv_fs_sendfile',
214+
'uv_fs_event_init',
215+
'uv_tty_init',
216+
'uv_tty_get_winsize',
217+
'uv_tty_set_mode',
218+
'uv_tty_reset_mode',
219+
'uv_tcp_getsockname',
220+
'uv_tcp_getpeername',
221+
'uv_udp_getsockname',
222+
'uv_resident_set_memory',
223+
'uv_ip4_name',
224+
'uv_ip6_name',
225+
'uv_poll_init',
226+
'uv_poll_start',
227+
'uv_poll_stop',
228+
'uv_fs_poll_init',
229+
'uv_fs_poll_start',
230+
'uv_fs_poll_stop',
231+
'uv_stop',
232+
'uv_signal_stop',
233+
234+
// https://github.com/JetBrains/phpstorm-stubs/pull/594
235+
'parallel\bootstrap',
236+
'parallel\run',
237+
238+
// https://youtrack.jetbrains.com/issue/WI-47038
239+
'pcov\collect',
240+
'pcov\start',
241+
'pcov\stop',
242+
'pcov\clear',
243+
'pcov\waiting',
244+
'pcov\memory',
245+
];
246+
247+
private const MISSING_CONSTANTS = [
248+
'STDIN',
249+
'STDOUT',
250+
'STDERR',
251+
252+
// https://youtrack.jetbrains.com/issue/WI-47038
253+
'pcov\all',
254+
'pcov\inclusive',
255+
'pcov\exclusive',
256+
];
257+
258+
private static $CLASSES;
259+
260+
private static $FUNCTIONS;
261+
28262
private static $CONSTANTS;
29263

30-
public function __construct()
264+
/**
265+
* @param array<string,string>|null $symbols
266+
* @param array<string,string> $source
267+
* @param string[] $missingSymbols
268+
*/
269+
private static function initSymbolList(?array &$symbols, array $source, array $missingSymbols): void
31270
{
32-
if (null === self::$CONSTANTS) {
33-
self::$CONSTANTS = PhpStormStubsMap::CONSTANTS;
34-
self::$CONSTANTS['STDIN'] = true;
35-
self::$CONSTANTS['STDOUT'] = true;
36-
self::$CONSTANTS['STDERR'] = true;
271+
if (null !== $symbols) {
272+
return;
37273
}
274+
275+
$symbols = array_fill_keys(
276+
array_merge(
277+
array_keys($source),
278+
$missingSymbols
279+
),
280+
true
281+
);
282+
}
283+
284+
public function __construct()
285+
{
286+
self::initSymbolList(self::$CLASSES, PhpStormStubsMap::CLASSES, self::MISSING_CLASSES);
287+
self::initSymbolList(self::$FUNCTIONS, PhpStormStubsMap::FUNCTIONS, self::MISSING_FUNCTIONS);
288+
self::initSymbolList(self::$CONSTANTS, PhpStormStubsMap::CONSTANTS, self::MISSING_CONSTANTS);
38289
}
39290

40291
public function isClassInternal(string $name): bool
41292
{
42-
return array_key_exists($name, PhpStormStubsMap::CLASSES);
293+
return isset(self::$CLASSES[$name]);
43294
}
44295

45296
public function isFunctionInternal(string $name): bool
46297
{
47-
return array_key_exists($name, PhpStormStubsMap::FUNCTIONS);
298+
return isset(self::$FUNCTIONS[$name]);
48299
}
49300

50301
public function isConstantInternal(string $name): bool
51302
{
52-
return array_key_exists($name, self::$CONSTANTS);
303+
return isset(self::$CONSTANTS[$name]);
53304
}
54305
}

0 commit comments

Comments
 (0)