Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sniff ordering causes side effect #329

Open
dereuromark opened this issue May 3, 2022 · 1 comment
Open

Sniff ordering causes side effect #329

dereuromark opened this issue May 3, 2022 · 1 comment
Labels

Comments

@dereuromark
Copy link
Contributor

When we have a non used use statement and move a FQCN inline to a use statement, it can get lost

namespace Spryker;

use Org\App\BazBatInterface; // seen as unused

class Test
{
    protected \Org\App\BazBatInterface $bazBat;

becomes

namespace Spryker;

class Test
{
    protected BazBatInterface $bazBat;

and not recoverable FQCN / use statement

@dereuromark dereuromark added the bug label May 3, 2022
@dereuromark
Copy link
Contributor Author

I tried squizlabs/PHP_CodeSniffer#3620 (comment) as per the comment

diff --git a/Spryker/Sniffs/Namespaces/UseStatementSniff.php b/Spryker/Sniffs/Namespaces/UseStatementSniff.php
--- a/Spryker/Sniffs/Namespaces/UseStatementSniff.php	(revision 0640063a7ae52af8f08a0e4b9e63b334ed529069)
+++ b/Spryker/Sniffs/Namespaces/UseStatementSniff.php	(date 1655979560894)
@@ -684,6 +684,10 @@
 
         if ($addedUseStatement['alias'] !== null) {
             $phpcsFile->fixer->replaceToken($lastIndex, $addedUseStatement['alias']);
+            for ($i = $startIndex; $i <= $lastSeparatorIndex; $i++) {
+                $phpcsFile->fixer->replaceToken($i, $tokens[$i]['content']);
+            }
+            $phpcsFile->fixer->replaceToken($lastSeparatorIndex + 1, $tokens[$lastSeparatorIndex + 1]['content']);
         }
 
         $phpcsFile->fixer->endChangeset();

but didnt seem to have any effect yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant