Skip to content

Commit 62154b4

Browse files
committed
Merge branch 'php-8.0/squiz-validvariablename-support-nullsafe-operator' of https://github.com/jrfnl/PHP_CodeSniffer
2 parents 222ea42 + ef289d9 commit 62154b4

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

src/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ protected function processVariable(File $phpcsFile, $stackPtr)
3838
}
3939

4040
$objOperator = $phpcsFile->findNext([T_WHITESPACE], ($stackPtr + 1), null, true);
41-
if ($tokens[$objOperator]['code'] === T_OBJECT_OPERATOR) {
41+
if ($tokens[$objOperator]['code'] === T_OBJECT_OPERATOR
42+
|| $tokens[$objOperator]['code'] === T_NULLSAFE_OBJECT_OPERATOR
43+
) {
4244
// Check to see if we are using a variable from an object.
4345
$var = $phpcsFile->findNext([T_WHITESPACE], ($objOperator + 1), null, true);
4446
if ($tokens[$var]['code'] === T_STRING) {

src/Standards/Squiz/Tests/NamingConventions/ValidVariableNameUnitTest.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,7 @@ $anonClass = new class() {
142142
}
143143
};
144144

145+
echo $obj?->varName;
146+
echo $obj?->var_name;
147+
echo $obj?->varname;
148+
echo $obj?->_varName;

src/Standards/Squiz/Tests/NamingConventions/ValidVariableNameUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public function getErrorList()
6060
123 => 1,
6161
138 => 1,
6262
141 => 1,
63+
146 => 1,
6364
];
6465

6566
return $errors;

0 commit comments

Comments
 (0)