Skip to content

Commit

Permalink
Variables::getMemberProperties(): add tests verifying support for nam…
Browse files Browse the repository at this point in the history
…espace operator in types

The commit which added support for the namespace keyword used as an operator to the `Collections::propertyTypeTokens[BC]()` methods implicitly added support for this to the `Variables::getMemberProperties()` method.

This commit adds a unit test to safeguard this support.

The same commit also _silently_ added support for the namespace operator to the `BCFile::getMemberProperties()` method. Namespace operators in property types are not supported yet in PHPCS itself and until they are, the fact that the `BCFile::getMemberProperties()` method supports this should be regarded as an artefact and not as official support.
  • Loading branch information
jrfnl committed Aug 31, 2020
1 parent cef0e13 commit 0941b32
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions PHPCSUtils/Utils/Variables.php
Expand Up @@ -81,6 +81,7 @@ class Variables
* other non-property variables passed to the method.
* - Defensive coding against incorrect calls to this method.
* - Support for PHP 8.0 union types.
* - Support for namespace operator in type declarations.
*
* @see \PHP_CodeSniffer\Files\File::getMemberProperties() Original source.
* @see \PHPCSUtils\BackCompat\BCFile::getMemberProperties() Cross-version compatible version of the original.
Expand Down
5 changes: 5 additions & 0 deletions Tests/Utils/Variables/GetMemberPropertiesDiffTest.inc
Expand Up @@ -52,3 +52,8 @@ $anon = class() {
// Intentional fatal error - duplicate types are not allowed in union types, but that's not the concern of the method.
public int |string| /*comment*/ INT $duplicateTypeInUnion;
};

class NSOperatorInType {
/* testNamespaceOperatorTypeHint */
public ?namespace\Name $prop;
}
12 changes: 12 additions & 0 deletions Tests/Utils/Variables/GetMemberPropertiesDiffTest.php
Expand Up @@ -232,6 +232,18 @@ public function dataGetMemberProperties()
'nullable_type' => false,
],
],
'namespace-operator-type-declaration' => [
'/* testNamespaceOperatorTypeHint */',
[
'scope' => 'public',
'scope_specified' => true,
'is_static' => false,
'type' => '?namespace\Name',
'type_token' => -4, // Offset from the T_VARIABLE token.
'type_end_token' => -2, // Offset from the T_VARIABLE token.
'nullable_type' => true,
],
],
];
}
}

0 comments on commit 0941b32

Please sign in to comment.