23
23
24
24
final class PhpCodeParser
25
25
{
26
- public static function getFromString (string $ code ): ParserContainer
27
- {
28
- return self ::getPhpFiles ($ code );
26
+ /**
27
+ * @param string $code
28
+ * @param string[] $composerAutoloaderProjectPaths
29
+ *
30
+ * @return \voku\SimplePhpParser\Parsers\Helper\ParserContainer
31
+ */
32
+ public static function getFromString (
33
+ string $ code ,
34
+ array $ composerAutoloaderProjectPaths = []
35
+ ): ParserContainer {
36
+ return self ::getPhpFiles (
37
+ $ code ,
38
+ $ composerAutoloaderProjectPaths
39
+ );
29
40
}
30
41
31
42
/**
32
43
* @param string $pathOrCode
33
44
* @param string[] $composerAutoloaderProjectPaths
45
+ * @param string[] $pathExcludeRegex
34
46
*
35
47
* @return \voku\SimplePhpParser\Parsers\Helper\ParserContainer
36
48
*
@@ -39,9 +51,13 @@ public static function getFromString(string $code): ParserContainer
39
51
*/
40
52
public static function getPhpFiles (
41
53
string $ pathOrCode ,
42
- array $ composerAutoloaderProjectPaths = []
54
+ array $ composerAutoloaderProjectPaths = [],
55
+ array $ pathExcludeRegex = []
43
56
): ParserContainer {
44
- $ phpCodes = self ::getCode ($ pathOrCode );
57
+ $ phpCodes = self ::getCode (
58
+ $ pathOrCode ,
59
+ $ pathExcludeRegex
60
+ );
45
61
46
62
$ parserContainer = new ParserContainer ();
47
63
$ visitor = new ASTVisitor ($ parserContainer );
@@ -235,14 +251,17 @@ public static function file_get_contents_with_cache(string $fileName, Cache $cac
235
251
}
236
252
237
253
/**
238
- * @param string $pathOrCode
254
+ * @param string $pathOrCode
255
+ * @param string[] $pathExcludeRegex
239
256
*
240
257
* @return array
241
258
*
242
259
* @psalm-return array<string, array{content: string, fileName: null|string}>
243
260
*/
244
- private static function getCode (string $ pathOrCode ): array
245
- {
261
+ private static function getCode (
262
+ string $ pathOrCode ,
263
+ array $ pathExcludeRegex = []
264
+ ): array {
246
265
// init
247
266
$ phpCodes = [];
248
267
/** @var SplFileInfo[] $phpFileIterators */
@@ -271,6 +290,12 @@ private static function getCode(string $pathOrCode): array
271
290
continue ;
272
291
}
273
292
293
+ foreach ($ pathExcludeRegex as $ regex ) {
294
+ if (\preg_match ($ regex , $ path )) {
295
+ continue 2 ;
296
+ }
297
+ }
298
+
274
299
$ phpFilePromises [] = Worker \enqueueCallable (
275
300
[self ::class, 'file_get_contents_with_cache ' ],
276
301
$ path ,
0 commit comments