only show wrong positioned var tag if it is present

This commit is contained in:
Marvin Kuhl 2021-08-03 11:02:54 +02:00
parent 6c1b52389d
commit 4bb9f54ca8
4 changed files with 18 additions and 2 deletions

1
composer.lock generated
View file

@ -1725,7 +1725,6 @@
"type": "github"
}
],
"abandoned": true,
"time": "2020-11-30T07:30:19+00:00"
},
{

View file

@ -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(

View file

@ -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());
}
}

View file

@ -0,0 +1,11 @@
<?php
namespace Inwebs\PhpCodesniffer\Sniffs\Annotations\data;
class Child extends PropertyOrder
{
/**
* @inheritDoc
*/
protected $test;
}