From 4bb9f54ca8ee4bdc1183891ed4d264c7a1727f16 Mon Sep 17 00:00:00 2001 From: Marvin Kuhl Date: Tue, 3 Aug 2021 11:02:54 +0200 Subject: [PATCH] only show wrong positioned var tag if it is present --- composer.lock | 1 - .../Annotations/VarIsLastTagOnPropertySniff.php | 2 +- .../Annotations/VarIsLastTagOnPropertySniffTest.php | 6 ++++++ tests/DigiComp/Sniffs/Annotations/data/Child.php | 11 +++++++++++ 4 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 tests/DigiComp/Sniffs/Annotations/data/Child.php diff --git a/composer.lock b/composer.lock index c0b3976..6defba8 100644 --- a/composer.lock +++ b/composer.lock @@ -1725,7 +1725,6 @@ "type": "github" } ], - "abandoned": true, "time": "2020-11-30T07:30:19+00:00" }, { diff --git a/src/DigiComp/Sniffs/Annotations/VarIsLastTagOnPropertySniff.php b/src/DigiComp/Sniffs/Annotations/VarIsLastTagOnPropertySniff.php index 25f651d..aac22cc 100644 --- a/src/DigiComp/Sniffs/Annotations/VarIsLastTagOnPropertySniff.php +++ b/src/DigiComp/Sniffs/Annotations/VarIsLastTagOnPropertySniff.php @@ -71,7 +71,7 @@ class VarIsLastTagOnPropertySniff extends AbstractVariableSniff } } } - if ($otherToken > $varToken) { + if ($varToken !== null && $otherToken > $varToken) { $fix = $phpcsFile->addFixableError('@var should be last property annotation', $varToken, 'VarNotLast'); if ($fix) { $this->moveVarTagToEndOfDoctype( diff --git a/tests/DigiComp/Sniffs/Annotations/VarIsLastTagOnPropertySniffTest.php b/tests/DigiComp/Sniffs/Annotations/VarIsLastTagOnPropertySniffTest.php index 8efdbc6..f45f737 100644 --- a/tests/DigiComp/Sniffs/Annotations/VarIsLastTagOnPropertySniffTest.php +++ b/tests/DigiComp/Sniffs/Annotations/VarIsLastTagOnPropertySniffTest.php @@ -11,4 +11,10 @@ class VarIsLastTagOnPropertySniffTest extends TestCase $report = self::checkFile(__DIR__ . '/data/PropertyOrder.php'); self::assertSame(2, $report->getErrorCount()); } + + public function testIgnoreVarTag(): void + { + $withoutErrors = self::checkFile(__DIR__ . '/data/Child.php'); + self::assertSame(0, $withoutErrors->getErrorCount()); + } } diff --git a/tests/DigiComp/Sniffs/Annotations/data/Child.php b/tests/DigiComp/Sniffs/Annotations/data/Child.php new file mode 100644 index 0000000..6089104 --- /dev/null +++ b/tests/DigiComp/Sniffs/Annotations/data/Child.php @@ -0,0 +1,11 @@ +