diff --git a/src/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php b/src/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php index ed2505817b..5f17a08b53 100644 --- a/src/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ b/src/Standards/Squiz/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -38,7 +38,9 @@ protected function processVariable(File $phpcsFile, $stackPtr) } $objOperator = $phpcsFile->findNext([T_WHITESPACE], ($stackPtr + 1), null, true); - if ($tokens[$objOperator]['code'] === T_OBJECT_OPERATOR) { + if ($tokens[$objOperator]['code'] === T_OBJECT_OPERATOR + || $tokens[$objOperator]['code'] === T_NULLSAFE_OBJECT_OPERATOR + ) { // Check to see if we are using a variable from an object. $var = $phpcsFile->findNext([T_WHITESPACE], ($objOperator + 1), null, true); if ($tokens[$var]['code'] === T_STRING) { diff --git a/src/Standards/Squiz/Tests/NamingConventions/ValidVariableNameUnitTest.inc b/src/Standards/Squiz/Tests/NamingConventions/ValidVariableNameUnitTest.inc index 5692d6b33b..c7b8a2b6b2 100644 --- a/src/Standards/Squiz/Tests/NamingConventions/ValidVariableNameUnitTest.inc +++ b/src/Standards/Squiz/Tests/NamingConventions/ValidVariableNameUnitTest.inc @@ -142,3 +142,7 @@ $anonClass = new class() { } }; +echo $obj?->varName; +echo $obj?->var_name; +echo $obj?->varname; +echo $obj?->_varName; diff --git a/src/Standards/Squiz/Tests/NamingConventions/ValidVariableNameUnitTest.php b/src/Standards/Squiz/Tests/NamingConventions/ValidVariableNameUnitTest.php index 4ec65e5e1a..aaa9d099a7 100644 --- a/src/Standards/Squiz/Tests/NamingConventions/ValidVariableNameUnitTest.php +++ b/src/Standards/Squiz/Tests/NamingConventions/ValidVariableNameUnitTest.php @@ -60,6 +60,7 @@ public function getErrorList() 123 => 1, 138 => 1, 141 => 1, + 146 => 1, ]; return $errors;