Skip to content

Commit

Permalink
Namespaces::getType: switch to objectOperators() method
Browse files Browse the repository at this point in the history
... and add a unit test using the nullsafe object operator.

No additional code is needed for the correct functioning of this method, as when the nullsafe object operator is not yet backfilled, the method will correctly signal on the object operator part of the token.
  • Loading branch information
jrfnl committed Aug 7, 2020
1 parent 50fc1d1 commit 0ec9ce6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion PHPCSUtils/Utils/Namespaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function getType(File $phpcsFile, $stackPtr)
+ Tokens::$castTokens
+ Tokens::$blockOpeners
+ Collections::$incrementDecrementOperators
+ Collections::$objectOperators;
+ Collections::objectOperators();

$findAfter[\T_OPEN_CURLY_BRACKET] = \T_OPEN_CURLY_BRACKET;
$findAfter[\T_OPEN_SQUARE_BRACKET] = \T_OPEN_SQUARE_BRACKET;
Expand Down
3 changes: 3 additions & 0 deletions Tests/Utils/Namespaces/NamespaceTypeTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ namespace\ClassName::$property++;
/* testNamespaceOperatorGlobalNamespaceStartOfStatementCombiWithNonConfusingToken3 */
namespace\CONSTANT['key'];

/* testNamespaceOperatorGlobalNamespaceStartOfStatementCombiWithNonConfusingToken4 */
namespace\functionReturningObj()?->chained();


/* testParseErrorScopedNamespaceDeclaration */
function testScope() {
Expand Down
7 changes: 7 additions & 0 deletions Tests/Utils/Namespaces/NamespaceTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ public function dataNamespaceType()
'operator' => true,
],
],
'namespace-operator-global-namespace-start-of-statement-with-non-confusing-token-4' => [
'/* testNamespaceOperatorGlobalNamespaceStartOfStatementCombiWithNonConfusingToken4 */',
[
'declaration' => false,
'operator' => true,
],
],
'parse-error-scoped-namespace-declaration' => [
'/* testParseErrorScopedNamespaceDeclaration */',
[
Expand Down

0 comments on commit 0ec9ce6

Please sign in to comment.