Skip to content

Commit 1dfe218

Browse files
committed
Fix PhpFileCleaner
1 parent 17f3f25 commit 1dfe218

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/Reflection/BetterReflection/SourceLocator/PhpFileCleaner.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function clean(string $contents, int $maxMatches): string
101101
continue;
102102
}
103103

104-
if ($char === '<' && $this->peek('<') && $this->match('{<<<[ \t]*+([\'"]?)([a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*+)\\1(?:\r\n|\n|\r)}A', $match)) {
104+
if ($char === '<' && $this->peek('<') && $this->match('{<<<[ \t]*+([\'"]?)([a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*+)\\1(?:\r\n|\n|\r)}A', $match) && $match !== null) {
105105
$this->index += strlen($match[0]);
106106
$this->skipHeredoc($match[2]);
107107
$clean .= 'null';
@@ -123,14 +123,15 @@ public function clean(string $contents, int $maxMatches): string
123123
$inType
124124
&& $char === 'c'
125125
&& $this->match('~.\b(?<![\$:>])const(\s++[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff\-]*+)~Ais', $match, $this->index - 1)
126+
&& $match !== null
126127
) {
127128
// It's invalid PHP but it does not matter
128129
$clean .= 'class_const' . $match[1];
129130
$this->index += strlen($match[0]) - 1;
130131
continue;
131132
}
132133

133-
if ($char === 'd' && $this->match('~.\b(?<![\$:>])define\s*+\(~Ais', $match, $this->index - 1)) {
134+
if ($char === 'd' && $this->match('~.\b(?<![\$:>])define\s*+\(~Ais', $match, $this->index - 1) && $match !== null) {
134135
$inDefine = true;
135136
$clean .= $match[0];
136137
$this->index += strlen($match[0]) - 1;
@@ -141,7 +142,7 @@ public function clean(string $contents, int $maxMatches): string
141142
$type = $this->typeConfig[$char];
142143

143144
if (substr($this->contents, $this->index, $type['length']) === $type['name']) {
144-
if ($maxMatches === 1 && $this->match($type['pattern'], $match, $this->index - 1)) {
145+
if ($maxMatches === 1 && $this->match($type['pattern'], $match, $this->index - 1) && $match !== null) {
145146
return $clean . $match[0];
146147
}
147148

@@ -150,7 +151,7 @@ public function clean(string $contents, int $maxMatches): string
150151
}
151152

152153
$this->index += 1;
153-
if ($this->match($this->restPattern, $match)) {
154+
if ($this->match($this->restPattern, $match) && $match !== null) {
154155
$clean .= $char . $match[0];
155156
$this->index += strlen($match[0]);
156157
} else {

0 commit comments

Comments
 (0)