Skip to content

Commit 809ac85

Browse files
committed
Merge branch 'feature/2.x-generic-classbracesameline-minor-fix' of https://github.com/jrfnl/PHP_CodeSniffer into 2.9
2 parents 6e6a3ed + 8041fc5 commit 809ac85

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

CodeSniffer/Standards/Generic/Sniffs/Classes/OpeningBraceSameLineSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
7474
$openingBrace = $tokens[$stackPtr]['scope_opener'];
7575

7676
// Is the brace on the same line as the class/interface/trait declaration ?
77-
$lastClassLineToken = $phpcsFile->findPrevious(T_STRING, ($openingBrace - 1), $stackPtr);
77+
$lastClassLineToken = $phpcsFile->findPrevious(T_WHITESPACE, ($openingBrace - 1), $stackPtr, true);
7878
$lastClassLine = $tokens[$lastClassLineToken]['line'];
7979
$braceLine = $tokens[$openingBrace]['line'];
8080
$lineDifference = ($braceLine - $lastClassLine);

CodeSniffer/Standards/Generic/Tests/Classes/OpeningBraceSameLineUnitTest.inc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,13 @@ class A_Class_With_Really_Long_Name_4
7979
{
8080

8181
}
82+
83+
// While this is ok again.
84+
class Test_Class_Bad_G /*some comment*/ {
85+
}
86+
87+
// And this is not.
88+
class Test_Class_Bad_G
89+
/*some comment*/
90+
{
91+
}

CodeSniffer/Standards/Generic/Tests/Classes/OpeningBraceSameLineUnitTest.inc.fixed

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,13 @@ class A_Class_With_Really_Long_Name_4
7979

8080

8181
}
82+
83+
// While this is ok again.
84+
class Test_Class_Bad_G /*some comment*/ {
85+
}
86+
87+
// And this is not.
88+
class Test_Class_Bad_G
89+
/*some comment*/ {
90+
91+
}

CodeSniffer/Standards/Generic/Tests/Classes/OpeningBraceSameLineUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public function getErrorList()
5454
47 => 1,
5555
70 => 1,
5656
79 => 1,
57+
90 => 1,
5758
);
5859

5960
}//end getErrorList()

0 commit comments

Comments
 (0)