-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PHP 8.0: "undo" namespaced names as single token
As per the proposal in 3041. This effectively "undoes" the new PHP 8.0 tokenization of identifier names for PHPCS 3.x. Includes extensive unit tests to ensure the correct re-tokenization as well as that the rest of the tokenization is not aversely affected by this change. Includes preventing `function ...` within a group use statement from breaking the retokenization. Includes fixing the nullable tokenization when combined with any of the new PHP 8 identifier name tokens.
- Loading branch information
Showing
5 changed files
with
1,531 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
tests/Core/Tokenizer/UndoNamespacedNameSingleTokenTest.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
<?php | ||
|
||
/* testNamespaceDeclaration */ | ||
namespace Package; | ||
|
||
/* testNamespaceDeclarationWithLevels */ | ||
namespace Vendor\SubLevel\Domain; | ||
|
||
/* testUseStatement */ | ||
use ClassName; | ||
|
||
/* testUseStatementWithLevels */ | ||
use Vendor\Level\Domain; | ||
|
||
/* testFunctionUseStatement */ | ||
use function function_name; | ||
|
||
/* testFunctionUseStatementWithLevels */ | ||
use function Vendor\Level\function_in_ns; | ||
|
||
/* testConstantUseStatement */ | ||
use const CONSTANT_NAME; | ||
|
||
/* testConstantUseStatementWithLevels */ | ||
use const Vendor\Level\OTHER_CONSTANT; | ||
|
||
/* testMultiUseUnqualified */ | ||
use UnqualifiedClassName, | ||
/* testMultiUsePartiallyQualified */ | ||
Sublevel\PartiallyClassName; | ||
|
||
/* testGroupUseStatement */ | ||
use Vendor\Level\{ | ||
AnotherDomain, | ||
function function_grouped, | ||
const CONSTANT_GROUPED, | ||
Sub\YetAnotherDomain, | ||
function SubLevelA\function_grouped_too, | ||
const SubLevelB\CONSTANT_GROUPED_TOO, | ||
}; | ||
|
||
/* testClassName */ | ||
class MyClass | ||
/* testExtendedFQN */ | ||
extends \Vendor\Level\FQN | ||
/* testImplementsRelative */ | ||
implements namespace\Name, | ||
/* testImplementsFQN */ | ||
\Fully\Qualified, | ||
/* testImplementsUnqualified */ | ||
Unqualified, | ||
/* testImplementsPartiallyQualified */ | ||
Sub\Level\Name | ||
{ | ||
/* testFunctionName */ | ||
public function function_name( | ||
/* testTypeDeclarationRelative */ | ||
namespace\Name $paramA, | ||
|
||
/* testTypeDeclarationFQN */ | ||
\Fully\Qualified\Name $paramB, | ||
|
||
/* testTypeDeclarationUnqualified */ | ||
Unqualified $paramC, | ||
|
||
/* testTypeDeclarationPartiallyQualified */ | ||
Sublevel\Name $paramD, | ||
|
||
/* testReturnTypeFQN */ | ||
) : \Name { | ||
|
||
try { | ||
/* testFunctionCallRelative */ | ||
echo NameSpace\function_name(); | ||
|
||
/* testFunctionCallFQN */ | ||
echo \Vendor\Package\function_name(); | ||
|
||
/* testFunctionCallUnqualified */ | ||
echo function_name(); | ||
|
||
/* testFunctionPartiallyQualified */ | ||
echo Level\function_name(); | ||
|
||
/* testCatchRelative */ | ||
} catch (namespace\SubLevel\Exception $e) { | ||
|
||
/* testCatchFQN */ | ||
} catch (\Exception $e) { | ||
|
||
/* testCatchUnqualified */ | ||
} catch (Exception $e) { | ||
|
||
/* testCatchPartiallyQualified */ | ||
} catch (Level\Exception $e) { | ||
} | ||
|
||
/* testNewRelative */ | ||
$obj = new namespace\ClassName(); | ||
|
||
/* testNewFQN */ | ||
$obj = new \Vendor\ClassName(); | ||
|
||
/* testNewUnqualified */ | ||
$obj = new ClassName; | ||
|
||
/* testNewPartiallyQualified */ | ||
$obj = new Level\ClassName; | ||
|
||
/* testDoubleColonRelative */ | ||
$value = namespace\ClassName::property; | ||
|
||
/* testDoubleColonFQN */ | ||
$value = \ClassName::static_function(); | ||
|
||
/* testDoubleColonUnqualified */ | ||
$value = ClassName::CONSTANT_NAME; | ||
|
||
/* testDoubleColonPartiallyQualified */ | ||
$value = Level\ClassName::CONSTANT_NAME['key']; | ||
|
||
/* testInstanceOfRelative */ | ||
$is = $obj instanceof namespace\ClassName; | ||
|
||
/* testInstanceOfFQN */ | ||
if ($obj instanceof \Full\ClassName) {} | ||
|
||
/* testInstanceOfUnqualified */ | ||
if ($a === $b && $obj instanceof ClassName && true) {} | ||
|
||
/* testInstanceOfPartiallyQualified */ | ||
$is = $obj instanceof Partially\ClassName; | ||
} | ||
} | ||
|
||
/* testInvalidInPHP8Whitespace */ | ||
namespace \ Sublevel | ||
\ function_name(); | ||
|
||
/* testInvalidInPHP8Comments */ | ||
$value = \Fully | ||
// phpcs:ignore Stnd.Cat.Sniff -- for reasons | ||
\Qualified | ||
/* comment */ | ||
\Name | ||
// comment | ||
:: function_name(); |
Oops, something went wrong.