You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do not close scope of ref reassignment when inside else (#306)
* Add test for unused variable
* Add more debug lines to reference processing
* Do not close scope of ref reassignment when inside else
* Verify all regexps are non-empty strings
This will please psalm, I hope.
* Add guard for empty preg_match_all in processVariableInString
if ($conditionPointer && $lastAssignmentPtr && $conditionPointer > $lastAssignmentPtr) {
1169
+
Helpers::debug("processVariableAsAssignment: not considering close of scope for '{$varName}' due to reference reassignment because it is conditional");
1170
+
}
1160
1171
// The referenced variable may have a different name, but we don't
1161
1172
// actually need to mark it as used in this case because the act of this
1162
1173
// assignment will mark it used on the next token.
@@ -1839,11 +1850,17 @@ protected function processVariableInString(File $phpcsFile, $stackPtr)
1839
1850
$tokens = $phpcsFile->getTokens();
1840
1851
$token = $tokens[$stackPtr];
1841
1852
1842
-
if (!preg_match_all(Constants::getDoubleQuotedVarRegexp(), $token['content'], $matches)) {
1853
+
$regexp = Constants::getDoubleQuotedVarRegexp();
1854
+
if (! empty($regexp) && !preg_match_all($regexp, $token['content'], $matches)) {
1855
+
Helpers::debug('processVariableInString: no variables found', $token);
1843
1856
return;
1844
1857
}
1845
1858
Helpers::debug('examining token for variable in string', $token);
1846
1859
1860
+
if (empty($matches)) {
1861
+
Helpers::debug('processVariableInString: no variables found after search', $token);
1862
+
return;
1863
+
}
1847
1864
foreach ($matches[1] as$varName) {
1848
1865
$varName = Helpers::normalizeVarName($varName);
1849
1866
@@ -1912,7 +1929,8 @@ protected function processCompactArguments(File $phpcsFile, $stackPtr, $argument
1912
1929
}
1913
1930
if ($argumentFirstToken['code'] === T_DOUBLE_QUOTED_STRING) {
1914
1931
// Double-quoted string literal.
1915
-
if (preg_match(Constants::getDoubleQuotedVarRegexp(), $argumentFirstToken['content'])) {
1932
+
$regexp = Constants::getDoubleQuotedVarRegexp();
1933
+
if (! empty($regexp) && preg_match($regexp, $argumentFirstToken['content'])) {
1916
1934
// Bail if the string needs variable expansion, that's runtime stuff.
1917
1935
continue;
1918
1936
}
@@ -1956,6 +1974,7 @@ protected function processCompact(File $phpcsFile, $stackPtr)
0 commit comments