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
33 changes: 27 additions & 6 deletions PHPCSUtils/Tokens/Collections.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,15 +301,13 @@ class Collections
];

/**
* Tokens types which can be encountered in the fully/partially qualified name of an OO structure.
*
* Example:
* ```php
* echo namespace\Sub\ClassName::method();
* ```
* DEPRECATED: Tokens types which can be encountered in the fully/partially qualified name of an OO structure.
*
* @since 1.0.0-alpha3
*
* @deprecated 1.0.0-alpha4 Use the {@see \PHPCSUtils\Tokens\Collections::namespacedNameTokens()}
* method instead.
*
* @var array <int|string> => <int|string>
*/
public static $OONameTokens = [
Expand Down Expand Up @@ -579,6 +577,29 @@ public static function functionDeclarationTokensBC()
return $tokens;
}

/**
* Tokens types which can be encountered in a fully, partially or unqualified name.
*
* Example:
* ```php
* echo namespace\Sub\ClassName::method();
* ```
*
* @since 1.0.0-alpha4
*
* @return array <int|string> => <int|string>
*/
public static function namespacedNameTokens()
{
$tokens = [
\T_NS_SEPARATOR => \T_NS_SEPARATOR,
\T_NAMESPACE => \T_NAMESPACE,
\T_STRING => \T_STRING,
];

return $tokens;
}

/**
* Object operators.
*
Expand Down
2 changes: 1 addition & 1 deletion PHPCSUtils/Utils/ControlStructures.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ public static function getCaughtExceptions(File $phpcsFile, $stackPtr)
continue;
}

if (isset(Collections::$OONameTokens[$tokens[$i]['code']]) === false) {
if (isset(Collections::namespacedNameTokens()[$tokens[$i]['code']]) === false) {
// Add the current exception to the result array.
$exceptions[] = [
'type' => $foundName,
Expand Down
2 changes: 1 addition & 1 deletion PHPCSUtils/Utils/ObjectDeclarations.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ private static function findNames(File $phpcsFile, $stackPtr, $keyword, $allowed
return false;
}

$find = Collections::$OONameTokens + Tokens::$emptyTokens;
$find = Collections::namespacedNameTokens() + Tokens::$emptyTokens;
$names = [];
$end = $keywordPtr;
do {
Expand Down
2 changes: 1 addition & 1 deletion PHPCSUtils/Utils/Operators.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public static function isReference(File $phpcsFile, $stackPtr)
return true;
} else {
$skip = Tokens::$emptyTokens;
$skip += Collections::$OONameTokens;
$skip += Collections::namespacedNameTokens();
$skip += Collections::$OOHierarchyKeywords;
$skip[] = \T_DOUBLE_COLON;

Expand Down
43 changes: 43 additions & 0 deletions Tests/Tokens/Collections/NamespacedNameTokensTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* PHPCSUtils, utility functions and classes for PHP_CodeSniffer sniff developers.
*
* @package PHPCSUtils
* @copyright 2019-2020 PHPCSUtils Contributors
* @license https://opensource.org/licenses/LGPL-3.0 LGPL3
* @link https://github.com/PHPCSStandards/PHPCSUtils
*/

namespace PHPCSUtils\Tests\Tokens\Collections;

use PHPCSUtils\Tokens\Collections;
use PHPUnit\Framework\TestCase;

/**
* Test class.
*
* @covers \PHPCSUtils\Tokens\Collections::namespacedNameTokens
*
* @group collections
*
* @since 1.0.0
*/
class NamespacedNameTokensTest extends TestCase
{

/**
* Test the method.
*
* @return void
*/
public function testNamespacedNameTokens()
{
$expected = [
\T_NS_SEPARATOR => \T_NS_SEPARATOR,
\T_NAMESPACE => \T_NAMESPACE,
\T_STRING => \T_STRING,
];

$this->assertSame($expected, Collections::namespacedNameTokens());
}
}