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
162 changes: 12 additions & 150 deletions PHPCSUtils/BackCompat/BCFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ public static function getMethodParameters(File $phpcsFile, $stackPtr)
*
* Changelog for the PHPCS native function:
* - Introduced in PHPCS 0.0.5.
* - The upstream method has received no significant updates since PHPCS 3.10.1.
* - The upstream method has received no significant updates since PHPCS 3.13.0.
*
* @see \PHP_CodeSniffer\Files\File::getMethodProperties() Original source.
* @see \PHPCSUtils\Utils\FunctionDeclarations::getProperties() PHPCSUtils native improved version.
Expand Down Expand Up @@ -554,7 +554,7 @@ public static function getMethodProperties(File $phpcsFile, $stackPtr)
*
* Changelog for the PHPCS native function:
* - Introduced in PHPCS 0.0.5.
* - PHPCS 3.12.0: report final properties
* - The upstream method has received no significant updates since PHPCS 3.13.0.
*
* @see \PHP_CodeSniffer\Files\File::getMemberProperties() Original source.
* @see \PHPCSUtils\Utils\Variables::getMemberProperties() PHPCSUtils native improved version.
Expand All @@ -573,145 +573,7 @@ public static function getMethodProperties(File $phpcsFile, $stackPtr)
*/
public static function getMemberProperties(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
if ($tokens[$stackPtr]['code'] !== T_VARIABLE) {
throw new RuntimeException('$stackPtr must be of type T_VARIABLE');
}

$conditions = array_keys($tokens[$stackPtr]['conditions']);
$ptr = array_pop($conditions);
if (isset($tokens[$ptr]) === false
|| ($tokens[$ptr]['code'] !== T_CLASS
&& $tokens[$ptr]['code'] !== T_ANON_CLASS
&& $tokens[$ptr]['code'] !== T_TRAIT)
) {
if (isset($tokens[$ptr]) === true
&& ($tokens[$ptr]['code'] === T_INTERFACE
|| $tokens[$ptr]['code'] === T_ENUM)
) {
// T_VARIABLEs in interfaces/enums can actually be method arguments
// but they won't be seen as being inside the method because there
// are no scope openers and closers for abstract methods. If it is in
// parentheses, we can be pretty sure it is a method argument.
if (isset($tokens[$stackPtr]['nested_parenthesis']) === false
|| empty($tokens[$stackPtr]['nested_parenthesis']) === true
) {
$error = 'Possible parse error: %ss may not include member vars';
$code = sprintf('Internal.ParseError.%sHasMemberVar', ucfirst($tokens[$ptr]['content']));
$data = [strtolower($tokens[$ptr]['content'])];
$phpcsFile->addWarning($error, $stackPtr, $code, $data);
return [];
}
} else {
throw new RuntimeException('$stackPtr is not a class member var');
}
}

// Make sure it's not a method parameter.
if (empty($tokens[$stackPtr]['nested_parenthesis']) === false) {
$parenthesis = array_keys($tokens[$stackPtr]['nested_parenthesis']);
$deepestOpen = array_pop($parenthesis);
if ($deepestOpen > $ptr
&& isset($tokens[$deepestOpen]['parenthesis_owner']) === true
&& $tokens[$tokens[$deepestOpen]['parenthesis_owner']]['code'] === T_FUNCTION
) {
throw new RuntimeException('$stackPtr is not a class member var');
}
}

$valid = Collections::propertyModifierKeywords();
$valid += Tokens::$emptyTokens;

$scope = 'public';
$scopeSpecified = false;
$isStatic = false;
$isReadonly = false;
$isFinal = false;

$startOfStatement = $phpcsFile->findPrevious(
[
T_SEMICOLON,
T_OPEN_CURLY_BRACKET,
T_CLOSE_CURLY_BRACKET,
T_ATTRIBUTE_END,
],
($stackPtr - 1)
);

for ($i = ($startOfStatement + 1); $i < $stackPtr; $i++) {
if (isset($valid[$tokens[$i]['code']]) === false) {
break;
}

switch ($tokens[$i]['code']) {
case T_PUBLIC:
$scope = 'public';
$scopeSpecified = true;
break;
case T_PRIVATE:
$scope = 'private';
$scopeSpecified = true;
break;
case T_PROTECTED:
$scope = 'protected';
$scopeSpecified = true;
break;
case T_STATIC:
$isStatic = true;
break;
case T_READONLY:
$isReadonly = true;
break;
case T_FINAL:
$isFinal = true;
break;
}
}

$type = '';
$typeToken = false;
$typeEndToken = false;
$nullableType = false;
$propertyTypeTokens = Collections::propertyTypeTokens();

if ($i < $stackPtr) {
// We've found a type.
for ($i; $i < $stackPtr; $i++) {
if ($tokens[$i]['code'] === T_VARIABLE) {
// Hit another variable in a group definition.
break;
}

if ($tokens[$i]['code'] === T_NULLABLE) {
$nullableType = true;
}

if (isset($propertyTypeTokens[$tokens[$i]['code']]) === true) {
$typeEndToken = $i;
if ($typeToken === false) {
$typeToken = $i;
}

$type .= $tokens[$i]['content'];
}
}

if ($type !== '' && $nullableType === true) {
$type = '?' . $type;
}
}

return [
'scope' => $scope,
'scope_specified' => $scopeSpecified,
'is_static' => $isStatic,
'is_readonly' => $isReadonly,
'is_final' => $isFinal,
'type' => $type,
'type_token' => $typeToken,
'type_end_token' => $typeEndToken,
'nullable_type' => $nullableType,
];
return $phpcsFile->getMemberProperties($stackPtr);
}

/**
Expand All @@ -730,7 +592,7 @@ public static function getMemberProperties(File $phpcsFile, $stackPtr)
*
* Changelog for the PHPCS native function:
* - Introduced in PHPCS 1.3.0.
* - The upstream method has received no significant updates since PHPCS 3.10.1.
* - The upstream method has received no significant updates since PHPCS 3.13.0.
*
* @see \PHP_CodeSniffer\Files\File::getClassProperties() Original source.
* @see \PHPCSUtils\Utils\ObjectDeclarations::getClassProperties() PHPCSUtils native improved version.
Expand Down Expand Up @@ -758,7 +620,7 @@ public static function getClassProperties(File $phpcsFile, $stackPtr)
*
* Changelog for the PHPCS native function:
* - Introduced in PHPCS 0.0.5.
* - The upstream method has received no significant updates since PHPCS 3.10.1.
* - The upstream method has received no significant updates since PHPCS 3.13.0.
*
* @see \PHP_CodeSniffer\Files\File::isReference() Original source.
* @see \PHPCSUtils\Utils\Operators::isReference() PHPCSUtils native improved version.
Expand All @@ -784,7 +646,7 @@ public static function isReference(File $phpcsFile, $stackPtr)
*
* Changelog for the PHPCS native function:
* - Introduced in PHPCS 0.0.5.
* - The upstream method has received no significant updates since PHPCS 3.10.1.
* - The upstream method has received no significant updates since PHPCS 3.13.0.
*
* @see \PHP_CodeSniffer\Files\File::getTokensAsString() Original source.
* @see \PHPCSUtils\Utils\GetTokensAsString Related set of functions.
Expand Down Expand Up @@ -813,7 +675,7 @@ public static function getTokensAsString(File $phpcsFile, $start, $length, $orig
*
* Changelog for the PHPCS native function:
* - Introduced in PHPCS 2.1.0.
* - The upstream method has received no significant updates since PHPCS 3.10.1.
* - The upstream method has received no significant updates since PHPCS 3.13.0.
*
* @see \PHP_CodeSniffer\Files\File::findStartOfStatement() Original source.
*
Expand All @@ -837,7 +699,7 @@ public static function findStartOfStatement(File $phpcsFile, $start, $ignore = n
*
* Changelog for the PHPCS native function:
* - Introduced in PHPCS 2.1.0.
* - The upstream method has received no significant updates since PHPCS 3.10.1.
* - The upstream method has received no significant updates since PHPCS 3.13.0.
*
* @see \PHP_CodeSniffer\Files\File::findEndOfStatement() Original source.
*
Expand All @@ -861,7 +723,7 @@ public static function findEndOfStatement(File $phpcsFile, $start, $ignore = nul
*
* Changelog for the PHPCS native function:
* - Introduced in PHPCS 0.0.5.
* - The upstream method has received no significant updates since PHPCS 3.10.1.
* - The upstream method has received no significant updates since PHPCS 3.13.0.
*
* @see \PHP_CodeSniffer\Files\File::hasCondition() Original source.
* @see \PHPCSUtils\Utils\Conditions::hasCondition() PHPCSUtils native alternative.
Expand All @@ -886,7 +748,7 @@ public static function hasCondition(File $phpcsFile, $stackPtr, $types)
*
* Changelog for the PHPCS native function:
* - Introduced in PHPCS 1.3.0.
* - The upstream method has received no significant updates since PHPCS 3.10.1.
* - The upstream method has received no significant updates since PHPCS 3.13.0.
*
* @see \PHP_CodeSniffer\Files\File::getCondition() Original source.
* @see \PHPCSUtils\Utils\Conditions::getCondition() More versatile alternative.
Expand Down Expand Up @@ -917,7 +779,7 @@ public static function getCondition(File $phpcsFile, $stackPtr, $type, $first =
*
* Changelog for the PHPCS native function:
* - Introduced in PHPCS 1.2.0.
* - The upstream method has received no significant updates since PHPCS 3.10.1.
* - The upstream method has received no significant updates since PHPCS 3.13.0.
*
* @see \PHP_CodeSniffer\Files\File::findExtendedClassName() Original source.
* @see \PHPCSUtils\Utils\ObjectDeclarations::findExtendedClassName() PHPCSUtils native improved version.
Expand All @@ -942,7 +804,7 @@ public static function findExtendedClassName(File $phpcsFile, $stackPtr)
*
* Changelog for the PHPCS native function:
* - Introduced in PHPCS 2.7.0.
* - The upstream method has received no significant updates since PHPCS 3.10.1.
* - The upstream method has received no significant updates since PHPCS 3.13.0.
*
* @see \PHP_CodeSniffer\Files\File::findImplementedInterfaceNames() Original source.
* @see \PHPCSUtils\Utils\ObjectDeclarations::findImplementedInterfaceNames() PHPCSUtils native improved version.
Expand Down
3 changes: 1 addition & 2 deletions PHPCSUtils/BackCompat/BCTokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ final class BCTokens

/**
* Handle calls to (undeclared) methods for token arrays which haven't received any
* changes since PHPCS 3.10.1.
* changes since PHPCS 3.13.0.
*
* @since 1.0.0
*
Expand Down Expand Up @@ -105,7 +105,6 @@ public static function __callStatic($name, $args)
*
* Changelog for the PHPCS native array:
* - Introduced in PHPCS 2.3.3.
* - PHPCS 3.7.2: `T_PARENT` added to the array.
* - PHPCS 4.0.0: `T_NAME_QUALIFIED`, `T_NAME_FULLY_QUALIFIED` and `T_NAME_RELATIVE` added to the array.
*
* @see \PHP_CodeSniffer\Util\Tokens::$functionNameTokens Original array.
Expand Down
17 changes: 10 additions & 7 deletions PHPCSUtils/Tokens/Collections.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,13 +467,16 @@ final class Collections
* @var array<int|string, int|string>
*/
private static $propertyModifierKeywords = [
\T_PUBLIC => \T_PUBLIC,
\T_PRIVATE => \T_PRIVATE,
\T_PROTECTED => \T_PROTECTED,
\T_STATIC => \T_STATIC,
\T_VAR => \T_VAR,
\T_READONLY => \T_READONLY,
\T_FINAL => \T_FINAL,
\T_PUBLIC => \T_PUBLIC,
\T_PUBLIC_SET => \T_PUBLIC_SET,
\T_PROTECTED => \T_PROTECTED,
\T_PROTECTED_SET => \T_PROTECTED_SET,
\T_PRIVATE => \T_PRIVATE,
\T_PRIVATE_SET => \T_PRIVATE_SET,
\T_STATIC => \T_STATIC,
\T_VAR => \T_VAR,
\T_READONLY => \T_READONLY,
\T_FINAL => \T_FINAL,
];

/**
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Whether you need to split an `array` into the individual items, are trying to de

Includes improved versions of the PHPCS native utility functions and plenty of new utility functions.

These functions are compatible with PHPCS 3.10.1 up to PHPCS `master`.
These functions are compatible with PHPCS 3.13.0 up to PHPCS `master`.

### A collection of static properties and methods for often-used token groups

Expand Down Expand Up @@ -78,7 +78,7 @@ To see detailed information about all the available abstract sniffs, utility fun
## Minimum Requirements

* PHP 5.4 or higher.
* [PHP_CodeSniffer] 3.10.1+.
* [PHP_CodeSniffer] 3.13.0+.
* Recommended PHP extensions for optimal functionality:
- PCRE with Unicode support (normally enabled by default)

Expand Down
9 changes: 6 additions & 3 deletions Tests/BackCompat/BCTokens/UnchangedTokenArraysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,12 @@ final class UnchangedTokenArraysTest extends TestCase
* @var array<int|string, int|string>
*/
private $scopeModifiers = [
\T_PRIVATE => \T_PRIVATE,
\T_PUBLIC => \T_PUBLIC,
\T_PROTECTED => \T_PROTECTED,
\T_PRIVATE => \T_PRIVATE,
\T_PUBLIC => \T_PUBLIC,
\T_PROTECTED => \T_PROTECTED,
\T_PUBLIC_SET => \T_PUBLIC_SET,
\T_PROTECTED_SET => \T_PROTECTED_SET,
\T_PRIVATE_SET => \T_PRIVATE_SET,
];

/**
Expand Down
2 changes: 1 addition & 1 deletion Tests/BackCompat/Helper/GetVersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testGetVersion()
}

if ($expected === 'lowest') {
$expected = '3.10.1';
$expected = '3.13.0';
}

$result = Helper::getVersion();
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"require" : {
"php" : ">=5.4",
"squizlabs/php_codesniffer" : "^3.10.1 || 4.0.x-dev@dev",
"squizlabs/php_codesniffer" : "^3.13.0 || 4.0.x-dev@dev",
"dealerdirect/phpcodesniffer-composer-installer" : "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7 || ^1.0"
},
"require-dev" : {
Expand Down
Loading