Closed (fixed)
Project:
Coder
Version:
8.x-2.x-dev
Component:
Coder Sniffer
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
11 Mar 2016 at 16:53 UTC
Updated:
1 Apr 2016 at 12:44 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
alexpottComment #3
alexpottHere's a failing test.
Comment #4
alexpottAnd here's the fix and also took the opportunity to remove dead code that confused me.
Comment #5
alexpottI used this on core and found a few more unused uses... see #2674408: Fix "Drupal.Classes.UnusedUseStatement" standard in core
Also tests pass...
Comment #6
dawehnerAny reason we don't use camelCase for this var as well?
I quickly tried another testcase, see interdiff, but this actually passes aready.
Comment #7
klausiSo this change is not related at all to the issue here? I'll make a separate commit for this.
Can we have a more elaborate comment what we are doing here? Like "Check if the referenced class is in the same namespace as the current file. If it is then the use statement is not necessary."
This will probably break horribly when people use multiple namespace {} constructs and use statements are not at the top of the file. But I think we can ignore that edge case and assume such code is unlikely and solve this another time if needed.
This is a bit unreliable if there are odd spaces or comments between all the parts. I think we should do a loop instead that uses PHP_CodeSniffer_Tokens::$emptyTokens to ignore that. Collecting all namsespace parts in that loop. And then do the same for the use statement.
Comment #8
alexpottThanks for the reviews
#6 - changed to camelCase
Re #7
Prevents this from being an issue an doing anything wrong.
Comment #9
alexpottHmmm #7.1 has already been committing to coder... rerolling.
Comment #11
klausiCommitted, thanks!
Fixed the coding standard errors during commit with
phpcs --standard=PHPCS coder_sniffer/Drupal/Sniffs/Classes/UnusedUseStatementSniff.php
and
phpcbf --standard=PHPCS coder_sniffer/Drupal/Sniffs/Classes/UnusedUseStatementSniff.php