Skip to content

Commit ea05e90

Browse files
committed
More fixes
1 parent a09a98d commit ea05e90

File tree

2 files changed

+12
-25
lines changed

2 files changed

+12
-25
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -130,31 +130,6 @@ parameters:
130130
count: 1
131131
path: src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocator.php
132132

133-
-
134-
message: "#^Parameter \\#1 \\$haystack of function strrpos expects string, string\\|null given\\.$#"
135-
count: 1
136-
path: src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocator.php
137-
138-
-
139-
message: "#^Parameter \\#1 \\$string of function substr expects string, string\\|null given\\.$#"
140-
count: 3
141-
path: src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocator.php
142-
143-
-
144-
message: "#^Parameter \\#2 \\$subject of function preg_match expects string, string\\|null given\\.$#"
145-
count: 1
146-
path: src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocator.php
147-
148-
-
149-
message: "#^Parameter \\#2 \\$subject of function preg_match_all expects string, string\\|null given\\.$#"
150-
count: 1
151-
path: src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocator.php
152-
153-
-
154-
message: "#^Parameter \\#3 \\$subject of function preg_replace expects array\\|string, string\\|null given\\.$#"
155-
count: 4
156-
path: src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocator.php
157-
158133
-
159134
message: "#^Method PHPStan\\\\Reflection\\\\ClassReflection\\:\\:__construct\\(\\) has parameter \\$reflection with generic class ReflectionClass but does not specify its types\\: T$#"
160135
count: 1

src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocator.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,24 @@ private function findSymbols(string $file): array
208208
}
209209
// strip strings
210210
$contents = preg_replace('{"[^"\\\\]*+(\\\\.[^"\\\\]*+)*+"|\'[^\'\\\\]*+(\\\\.[^\'\\\\]*+)*+\'}s', 'null', $contents);
211+
if ($contents === null) {
212+
return ['classes' => [], 'functions' => []];
213+
}
211214
// strip leading non-php code if needed
212215
if (substr($contents, 0, 2) !== '<?') {
213216
$contents = preg_replace('{^.+?<\?}s', '<?', $contents, 1, $replacements);
217+
if ($contents === null) {
218+
return ['classes' => [], 'functions' => []];
219+
}
214220
if ($replacements === 0) {
215221
return ['classes' => [], 'functions' => []];
216222
}
217223
}
218224
// strip non-php blocks in the file
219225
$contents = preg_replace('{\?>(?:[^<]++|<(?!\?))*+<\?}s', '?><?', $contents);
226+
if ($contents === null) {
227+
return ['classes' => [], 'functions' => []];
228+
}
220229
// strip trailing non-php code if needed
221230
$pos = strrpos($contents, '?>');
222231
if ($pos !== false && strpos(substr($contents, $pos), '<?') === false) {
@@ -225,6 +234,9 @@ private function findSymbols(string $file): array
225234
// strip comments if short open tags are in the file
226235
if (preg_match('{(<\?)(?!(php|hh))}i', $contents)) {
227236
$contents = preg_replace('{//.* | /\*(?:[^*]++|\*(?!/))*\*/}x', '', $contents);
237+
if ($contents === null) {
238+
return ['classes' => [], 'functions' => []];
239+
}
228240
}
229241

230242
preg_match_all('{

0 commit comments

Comments
 (0)