Skip to content

Commit

Permalink
Fix use declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Jan 6, 2020
1 parent 48302f1 commit 657a6d2
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Standards/PSR12/Sniffs/Traits/UseDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@ public function process(File $phpcsFile, $stackPtr)
}

$lastValidContent = $i;

continue;
}

break;
}
}//end for

if ($tokens[$lastValidContent]['line'] !== ($tokens[$opener]['line'] + 1)) {
$error = 'The first trait import statement must be declared on the first non-comment line after the %s opening brace';
Expand Down
37 changes: 37 additions & 0 deletions src/Standards/PSR12/Tests/Traits/UseDeclarationUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,40 @@ class MyExample
use Trait3;

}

class Foo implements Bar
{
/*
* Comment here;
*/
use Baz;
}

class Foo implements Bar
{
// Comment here;
use Baz;
}

class Foo implements Bar
{
/**
* Comment here;
*/
/**
* Another Comment here;
*/
use Baz;
}

class Foo implements Bar
{
/**
* Comment here;
*/
public $foo;
/**
* Comment here;
*/
use Baz;
}
37 changes: 37 additions & 0 deletions src/Standards/PSR12/Tests/Traits/UseDeclarationUnitTest.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,40 @@ class MyExample
// comment here
use Trait3;
}

class Foo implements Bar
{
/*
* Comment here;
*/
use Baz;
}

class Foo implements Bar
{
// Comment here;
use Baz;
}

class Foo implements Bar
{
/**
* Comment here;
*/
/**
* Another Comment here;
*/
use Baz;
}

class Foo implements Bar
{
/**
* Comment here;
*/
public $foo;
/**
* Comment here;
*/
use Baz;
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function getErrorList()
157 => 1,
165 => 1,
170 => 1,
208 => 1,
];

}//end getErrorList()
Expand Down

0 comments on commit 657a6d2

Please sign in to comment.