Skip to content

Commit da031f9

Browse files
committed
Fix the getDataRegexMatch.
1 parent 7d183ce commit da031f9

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/StringDataParserTrait.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,13 @@ public function getParsedDomObject(bool $reParse = false): \DOMDocument
104104
*
105105
* @return array|string
106106
*/
107-
public function getDataRegexMatch(string $regex, $group = -1, int $fill_size = 0)
107+
public function getDataRegexMatch(string $regex, $group = null, int $fill_size = 0)
108108
{
109109
$is_matched = preg_match($regex, $this->stringDataIsWaitingToBeParsed, $matches);
110110

111-
if ($group >= 0) {
111+
if ($group !== null && $group >= 0) {
112112
if ($is_matched) {
113-
return $matches[$group];
113+
return $matches[$group] ?? '';
114114
} else {
115115
return '';
116116
}
@@ -119,9 +119,9 @@ public function getDataRegexMatch(string $regex, $group = -1, int $fill_size = 0
119119
if ($group !== null) {
120120
array_shift($matches);
121121
}
122-
return $matches;
122+
return $matches ?: [];
123123
} else {
124-
return $fill_size > 0 ? array_fill(0, $fill_size, '') : [];
124+
return $fill_size > 0 ? array_fill(0, $fill_size, '') : $matches;
125125
}
126126
}
127127
}
@@ -136,4 +136,4 @@ public function isExistInData(string $needle, int $offset = 0)
136136
return strpos($this->stringDataIsWaitingToBeParsed, $needle, $offset) !== false;
137137
}
138138

139-
}
139+
}

0 commit comments

Comments
 (0)