Skip to content

Commit

Permalink
Merge branch 'feature/generic-one-oo-perfile-sniff-efficiency-tweak' of
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed May 31, 2022
2 parents f88fcbc + e2bbbce commit 5e27199
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/Standards/Generic/Sniffs/Files/OneClassPerFileSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
8 changes: 7 additions & 1 deletion src/Standards/Generic/Sniffs/Files/OneTraitPerFileSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 5e27199

Please sign in to comment.