Skip to content

Commit cc1069d

Browse files
committed
Fixed bug #2665 : PSR12.Files.ImportStatement should not apply to traits
1 parent 35256b6 commit cc1069d

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
3939
-- Thanks to Juliette Reinders Folmer for the patch
4040
- Fixed bug #2663 : Generic.NamingConventions.ConstructorName complains about old constructor in interfaces
4141
- Fixed bug #2664 : PSR12.Files.OpenTag incorrectly identifies PHP file with only an opening tag
42+
- Fixed bug #2665 : PSR12.Files.ImportStatement should not apply to traits
4243
</notes>
4344
<contents>
4445
<dir name="/">

src/Standards/PSR12/Sniffs/Files/ImportStatementSniff.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ public function process(File $phpcsFile, $stackPtr)
4848
return;
4949
}
5050

51+
if ($phpcsFile->hasCondition($stackPtr, Tokens::$ooScopeTokens) === true) {
52+
// This rule inly applies to import statements.
53+
return;
54+
}
55+
5156
if ($tokens[$next]['code'] === T_STRING
5257
&& (strtolower($tokens[$next]['content']) === 'function'
5358
|| strtolower($tokens[$next]['content']) === 'const')

src/Standards/PSR12/Tests/Files/ImportStatementUnitTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public function getErrorList()
2929
2 => 1,
3030
4 => 1,
3131
7 => 1,
32-
14 => 1,
3332
];
3433

3534
}//end getErrorList()

0 commit comments

Comments
 (0)