diff --git a/src/Standards/Generic/Sniffs/Files/OneClassPerFileSniff.php b/src/Standards/Generic/Sniffs/Files/OneClassPerFileSniff.php index 9bcc00c1c2..52d5d84c74 100644 --- a/src/Standards/Generic/Sniffs/Files/OneClassPerFileSniff.php +++ b/src/Standards/Generic/Sniffs/Files/OneClassPerFileSniff.php @@ -39,7 +39,13 @@ public function register() */ public function process(File $phpcsFile, $stackPtr) { - $nextClass = $phpcsFile->findNext($this->register(), ($stackPtr + 1)); + $tokens = $phpcsFile->getTokens(); + $start = ($stackPtr + 1); + if (isset($tokens[$stackPtr]['scope_closer']) === true) { + $start = ($tokens[$stackPtr]['scope_closer'] + 1); + } + + $nextClass = $phpcsFile->findNext($this->register(), $start); if ($nextClass !== false) { $error = 'Only one class is allowed in a file'; $phpcsFile->addError($error, $nextClass, 'MultipleFound'); diff --git a/src/Standards/Generic/Sniffs/Files/OneInterfacePerFileSniff.php b/src/Standards/Generic/Sniffs/Files/OneInterfacePerFileSniff.php index f7cfa8d30b..9a6f5bccd5 100644 --- a/src/Standards/Generic/Sniffs/Files/OneInterfacePerFileSniff.php +++ b/src/Standards/Generic/Sniffs/Files/OneInterfacePerFileSniff.php @@ -39,7 +39,13 @@ public function register() */ public function process(File $phpcsFile, $stackPtr) { - $nextInterface = $phpcsFile->findNext($this->register(), ($stackPtr + 1)); + $tokens = $phpcsFile->getTokens(); + $start = ($stackPtr + 1); + if (isset($tokens[$stackPtr]['scope_closer']) === true) { + $start = ($tokens[$stackPtr]['scope_closer'] + 1); + } + + $nextInterface = $phpcsFile->findNext($this->register(), $start); if ($nextInterface !== false) { $error = 'Only one interface is allowed in a file'; $phpcsFile->addError($error, $nextInterface, 'MultipleFound'); diff --git a/src/Standards/Generic/Sniffs/Files/OneObjectStructurePerFileSniff.php b/src/Standards/Generic/Sniffs/Files/OneObjectStructurePerFileSniff.php index 939086d3f0..4d417e069e 100644 --- a/src/Standards/Generic/Sniffs/Files/OneObjectStructurePerFileSniff.php +++ b/src/Standards/Generic/Sniffs/Files/OneObjectStructurePerFileSniff.php @@ -44,7 +44,13 @@ public function register() */ public function process(File $phpcsFile, $stackPtr) { - $nextClass = $phpcsFile->findNext($this->register(), ($stackPtr + 1)); + $tokens = $phpcsFile->getTokens(); + $start = ($stackPtr + 1); + if (isset($tokens[$stackPtr]['scope_closer']) === true) { + $start = ($tokens[$stackPtr]['scope_closer'] + 1); + } + + $nextClass = $phpcsFile->findNext($this->register(), $start); if ($nextClass !== false) { $error = 'Only one object structure is allowed in a file'; $phpcsFile->addError($error, $nextClass, 'MultipleFound'); diff --git a/src/Standards/Generic/Sniffs/Files/OneTraitPerFileSniff.php b/src/Standards/Generic/Sniffs/Files/OneTraitPerFileSniff.php index dd97da85b4..7ae523f70e 100644 --- a/src/Standards/Generic/Sniffs/Files/OneTraitPerFileSniff.php +++ b/src/Standards/Generic/Sniffs/Files/OneTraitPerFileSniff.php @@ -39,7 +39,13 @@ public function register() */ public function process(File $phpcsFile, $stackPtr) { - $nextClass = $phpcsFile->findNext($this->register(), ($stackPtr + 1)); + $tokens = $phpcsFile->getTokens(); + $start = ($stackPtr + 1); + if (isset($tokens[$stackPtr]['scope_closer']) === true) { + $start = ($tokens[$stackPtr]['scope_closer'] + 1); + } + + $nextClass = $phpcsFile->findNext($this->register(), $start); if ($nextClass !== false) { $error = 'Only one trait is allowed in a file'; $phpcsFile->addError($error, $nextClass, 'MultipleFound');