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

False negative ReferenceViaFullyQualifiedName in a foreach #1710

Open
MauricioFauth opened this issue Nov 9, 2024 · 0 comments
Open

False negative ReferenceViaFullyQualifiedName in a foreach #1710

MauricioFauth opened this issue Nov 9, 2024 · 0 comments

Comments

@MauricioFauth
Copy link

diff --git a/tests/Sniffs/Namespaces/data/fixableReferenceViaFullyQualifiedName.fixed.php b/tests/Sniffs/Namespaces/data/fixableReferenceViaFullyQualifiedName.fixed.php
index bac26b1a..f78195e1 100644
--- a/tests/Sniffs/Namespaces/data/fixableReferenceViaFullyQualifiedName.fixed.php
+++ b/tests/Sniffs/Namespaces/data/fixableReferenceViaFullyQualifiedName.fixed.php
@@ -11,6 +11,7 @@ use function Boo\foo;
 use const Boo\FOO;
 use function min;
 use const PHP_VERSION;
+use Foo\BarTwo;
 
 class Bar extends ObjectPrototype implements Iterator
 {
@@ -27,6 +28,12 @@ class Bar extends ObjectPrototype implements Iterator
                FOO;
                min(1, 2);
                PHP_VERSION;
+               foreach (BarTwo::$values as BarTwo::$value) {
+                       echo BarTwo::$value;
+               }
+               foreach (BarTwo::$values as BarTwo::$key => BarTwo::$value) {
+                       echo BarTwo::$key . BarTwo::$value;
+               }
        }
 
        public function foo(DoctrineColumn $doctrineColumn): \Nette\ObjectPrototype
diff --git a/tests/Sniffs/Namespaces/data/fixableReferenceViaFullyQualifiedName.php b/tests/Sniffs/Namespaces/data/fixableReferenceViaFullyQualifiedName.php
index 9906115a..45111b7e 100644
--- a/tests/Sniffs/Namespaces/data/fixableReferenceViaFullyQualifiedName.php
+++ b/tests/Sniffs/Namespaces/data/fixableReferenceViaFullyQualifiedName.php
@@ -19,6 +19,12 @@ class Bar extends \ObjectPrototype implements \Iterator
                \Boo\FOO;
                min(1, 2);
                PHP_VERSION;
+               foreach (\Foo\BarTwo::$values as \Foo\BarTwo::$value) {
+                       echo \Foo\BarTwo::$value;
+               }
+               foreach (\Foo\BarTwo::$values as \Foo\BarTwo::$key => \Foo\BarTwo::$value) {
+                       echo \Foo\BarTwo::$key . \Foo\BarTwo::$value;
+               }
        }
 
        public function foo(\Doctrine\ORM\Mapping\Column $doctrineColumn): \Nette\ObjectPrototype
PHPUnit 10.5.38 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.2.25 with Xdebug 3.3.2
Configuration: slevomat/coding-standard/phpunit.xml.dist

F

Time: 00:00.431, Memory: 30.00 MB

There was 1 failure:

1) SlevomatCodingStandard\Sniffs\Namespaces\ReferenceUsedNamesOnlySniffTest::testFixableReferenceViaFullyQualifiedOrGlobalFallbackName
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
 		FOO;\n
 		min(1, 2);\n
 		PHP_VERSION;\n
-		foreach (BarTwo::$values as BarTwo::$value) {\n
+		foreach (BarTwo::$values as \Foo\BarTwo::$value) {\n
 			echo BarTwo::$value;\n
 		}\n
-		foreach (BarTwo::$values as BarTwo::$key => BarTwo::$value) {\n
+		foreach (BarTwo::$values as \Foo\BarTwo::$key => BarTwo::$value) {\n
 			echo BarTwo::$key . BarTwo::$value;\n
 		}\n
 	}\n

slevomat/coding-standard/SlevomatCodingStandard/Sniffs/TestCase.php:166
slevomat/coding-standard/tests/Sniffs/Namespaces/ReferenceUsedNamesOnlySniffTest.php:529

FAILURES!
Tests: 1, Assertions: 2, Failures: 1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant