diff --git a/src/Standards/PEAR/Sniffs/NamingConventions/ValidVariableNameSniff.php b/src/Standards/PEAR/Sniffs/NamingConventions/ValidVariableNameSniff.php index 48674b1e80..8bc9351285 100644 --- a/src/Standards/PEAR/Sniffs/NamingConventions/ValidVariableNameSniff.php +++ b/src/Standards/PEAR/Sniffs/NamingConventions/ValidVariableNameSniff.php @@ -10,12 +10,27 @@ namespace PHP_CodeSniffer\Standards\PEAR\Sniffs\NamingConventions; use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\AbstractScopeSniff; use PHP_CodeSniffer\Sniffs\AbstractVariableSniff; +use PHP_CodeSniffer\Util\Tokens; class ValidVariableNameSniff extends AbstractVariableSniff { + /** + * Only listen to variables within OO scopes. + */ + public function __construct() + { + $scopes = Tokens::$ooScopeTokens; + $listen = [T_VARIABLE]; + + AbstractScopeSniff::__construct($scopes, $listen, false); + + }//end __construct() + + /** * Processes class member variables. * diff --git a/src/Standards/PSR2/Sniffs/Classes/PropertyDeclarationSniff.php b/src/Standards/PSR2/Sniffs/Classes/PropertyDeclarationSniff.php index 29d7023ea9..04c5535114 100644 --- a/src/Standards/PSR2/Sniffs/Classes/PropertyDeclarationSniff.php +++ b/src/Standards/PSR2/Sniffs/Classes/PropertyDeclarationSniff.php @@ -11,6 +11,7 @@ use Exception; use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\AbstractScopeSniff; use PHP_CodeSniffer\Sniffs\AbstractVariableSniff; use PHP_CodeSniffer\Util\Tokens; @@ -18,6 +19,19 @@ class PropertyDeclarationSniff extends AbstractVariableSniff { + /** + * Only listen to variables within OO scopes. + */ + public function __construct() + { + $scopes = Tokens::$ooScopeTokens; + $listen = [T_VARIABLE]; + + AbstractScopeSniff::__construct($scopes, $listen, false); + + }//end __construct() + + /** * Processes the function tokens within the class. * diff --git a/src/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php b/src/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php index 76fbc6dca6..050ed88e87 100644 --- a/src/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php +++ b/src/Standards/Squiz/Sniffs/Commenting/VariableCommentSniff.php @@ -10,13 +10,28 @@ namespace PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting; use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\AbstractScopeSniff; use PHP_CodeSniffer\Sniffs\AbstractVariableSniff; use PHP_CodeSniffer\Util\Common; +use PHP_CodeSniffer\Util\Tokens; class VariableCommentSniff extends AbstractVariableSniff { + /** + * Only listen to variables within OO scopes. + */ + public function __construct() + { + $scopes = Tokens::$ooScopeTokens; + $listen = [T_VARIABLE]; + + AbstractScopeSniff::__construct($scopes, $listen, false); + + }//end __construct() + + /** * Called to process class member vars. * diff --git a/src/Standards/Squiz/Sniffs/Scope/MemberVarScopeSniff.php b/src/Standards/Squiz/Sniffs/Scope/MemberVarScopeSniff.php index 3d1c83f019..b15116701b 100644 --- a/src/Standards/Squiz/Sniffs/Scope/MemberVarScopeSniff.php +++ b/src/Standards/Squiz/Sniffs/Scope/MemberVarScopeSniff.php @@ -10,12 +10,27 @@ namespace PHP_CodeSniffer\Standards\Squiz\Sniffs\Scope; use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\AbstractScopeSniff; use PHP_CodeSniffer\Sniffs\AbstractVariableSniff; +use PHP_CodeSniffer\Util\Tokens; class MemberVarScopeSniff extends AbstractVariableSniff { + /** + * Only listen to variables within OO scopes. + */ + public function __construct() + { + $scopes = Tokens::$ooScopeTokens; + $listen = [T_VARIABLE]; + + AbstractScopeSniff::__construct($scopes, $listen, false); + + }//end __construct() + + /** * Processes the function tokens within the class. * diff --git a/src/Standards/Squiz/Sniffs/WhiteSpace/MemberVarSpacingSniff.php b/src/Standards/Squiz/Sniffs/WhiteSpace/MemberVarSpacingSniff.php index 773d25d4f5..8840ee0cc0 100644 --- a/src/Standards/Squiz/Sniffs/WhiteSpace/MemberVarSpacingSniff.php +++ b/src/Standards/Squiz/Sniffs/WhiteSpace/MemberVarSpacingSniff.php @@ -10,6 +10,7 @@ namespace PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace; use PHP_CodeSniffer\Files\File; +use PHP_CodeSniffer\Sniffs\AbstractScopeSniff; use PHP_CodeSniffer\Sniffs\AbstractVariableSniff; use PHP_CodeSniffer\Util\Tokens; @@ -31,6 +32,19 @@ class MemberVarSpacingSniff extends AbstractVariableSniff public $spacingBeforeFirst = 1; + /** + * Only listen to variables within OO scopes. + */ + public function __construct() + { + $scopes = Tokens::$ooScopeTokens; + $listen = [T_VARIABLE]; + + AbstractScopeSniff::__construct($scopes, $listen, false); + + }//end __construct() + + /** * Processes the function tokens within the class. *