Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions PhpCollective/Sniffs/AbstractSniffs/AbstractSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ protected function getGlobalFunctionName(File $phpcsFile, int $stackPtr): ?strin
{
$tokens = $phpcsFile->getTokens();

// An attribute name sits in front of a parenthesis just like a call does, but it names a
// class. Every token between `#[` and its closer carries the opener, including grouped
// attributes after a comma.
if (isset($tokens[$stackPtr]['attribute_opener'])) {
return null;
}

if ($tokens[$stackPtr]['code'] === T_STRING) {
return strtolower($tokens[$stackPtr]['content']);
}
Expand Down
7 changes: 7 additions & 0 deletions tests/_data/RemoveFunctionAlias/after.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

class FixMe
{

/**
* Attribute names sit in front of a parenthesis but name a class, not a function.
*/
#[Pos(1), Chop(2)]
#[\Join(3)]
public int $attributed = 1;
/**
* Type check aliases.
*/
Expand Down
7 changes: 7 additions & 0 deletions tests/_data/RemoveFunctionAlias/before.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

class FixMe
{

/**
* Attribute names sit in front of a parenthesis but name a class, not a function.
*/
#[Pos(1), Chop(2)]
#[\Join(3)]
public int $attributed = 1;
/**
* Type check aliases.
*/
Expand Down
Loading