Skip to content

Commit 5e27199

Browse files
committed
Merge branch 'feature/generic-one-oo-perfile-sniff-efficiency-tweak' of https://github.com/jrfnl/PHP_CodeSniffer
2 parents f88fcbc + e2bbbce commit 5e27199

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

src/Standards/Generic/Sniffs/Files/OneClassPerFileSniff.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ public function register()
3939
*/
4040
public function process(File $phpcsFile, $stackPtr)
4141
{
42-
$nextClass = $phpcsFile->findNext($this->register(), ($stackPtr + 1));
42+
$tokens = $phpcsFile->getTokens();
43+
$start = ($stackPtr + 1);
44+
if (isset($tokens[$stackPtr]['scope_closer']) === true) {
45+
$start = ($tokens[$stackPtr]['scope_closer'] + 1);
46+
}
47+
48+
$nextClass = $phpcsFile->findNext($this->register(), $start);
4349
if ($nextClass !== false) {
4450
$error = 'Only one class is allowed in a file';
4551
$phpcsFile->addError($error, $nextClass, 'MultipleFound');

src/Standards/Generic/Sniffs/Files/OneInterfacePerFileSniff.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ public function register()
3939
*/
4040
public function process(File $phpcsFile, $stackPtr)
4141
{
42-
$nextInterface = $phpcsFile->findNext($this->register(), ($stackPtr + 1));
42+
$tokens = $phpcsFile->getTokens();
43+
$start = ($stackPtr + 1);
44+
if (isset($tokens[$stackPtr]['scope_closer']) === true) {
45+
$start = ($tokens[$stackPtr]['scope_closer'] + 1);
46+
}
47+
48+
$nextInterface = $phpcsFile->findNext($this->register(), $start);
4349
if ($nextInterface !== false) {
4450
$error = 'Only one interface is allowed in a file';
4551
$phpcsFile->addError($error, $nextInterface, 'MultipleFound');

src/Standards/Generic/Sniffs/Files/OneObjectStructurePerFileSniff.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ public function register()
4444
*/
4545
public function process(File $phpcsFile, $stackPtr)
4646
{
47-
$nextClass = $phpcsFile->findNext($this->register(), ($stackPtr + 1));
47+
$tokens = $phpcsFile->getTokens();
48+
$start = ($stackPtr + 1);
49+
if (isset($tokens[$stackPtr]['scope_closer']) === true) {
50+
$start = ($tokens[$stackPtr]['scope_closer'] + 1);
51+
}
52+
53+
$nextClass = $phpcsFile->findNext($this->register(), $start);
4854
if ($nextClass !== false) {
4955
$error = 'Only one object structure is allowed in a file';
5056
$phpcsFile->addError($error, $nextClass, 'MultipleFound');

src/Standards/Generic/Sniffs/Files/OneTraitPerFileSniff.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ public function register()
3939
*/
4040
public function process(File $phpcsFile, $stackPtr)
4141
{
42-
$nextClass = $phpcsFile->findNext($this->register(), ($stackPtr + 1));
42+
$tokens = $phpcsFile->getTokens();
43+
$start = ($stackPtr + 1);
44+
if (isset($tokens[$stackPtr]['scope_closer']) === true) {
45+
$start = ($tokens[$stackPtr]['scope_closer'] + 1);
46+
}
47+
48+
$nextClass = $phpcsFile->findNext($this->register(), $start);
4349
if ($nextClass !== false) {
4450
$error = 'Only one trait is allowed in a file';
4551
$phpcsFile->addError($error, $nextClass, 'MultipleFound');

0 commit comments

Comments
 (0)