Skip to content

Commit 6fed215

Browse files
committed
BCFile::getMemberProperties(): make compatible with PHPCS 4.x
... and remove some redundant end comments.
1 parent 9ae615a commit 6fed215

File tree

2 files changed

+12
-36
lines changed

2 files changed

+12
-36
lines changed

PHPCSUtils/BackCompat/BCFile.php

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ public static function getMemberProperties(File $phpcsFile, $stackPtr)
605605
} else {
606606
throw new RuntimeException('$stackPtr is not a class member var');
607607
}
608-
}//end if
608+
}
609609

610610
// Make sure it's not a method parameter.
611611
if (empty($tokens[$stackPtr]['nested_parenthesis']) === false) {
@@ -619,16 +619,7 @@ public static function getMemberProperties(File $phpcsFile, $stackPtr)
619619
}
620620
}
621621

622-
$valid = [
623-
T_PUBLIC => T_PUBLIC,
624-
T_PRIVATE => T_PRIVATE,
625-
T_PROTECTED => T_PROTECTED,
626-
T_STATIC => T_STATIC,
627-
T_VAR => T_VAR,
628-
T_READONLY => T_READONLY,
629-
T_FINAL => T_FINAL,
630-
];
631-
622+
$valid = Collections::propertyModifierKeywords();
632623
$valid += Tokens::$emptyTokens;
633624

634625
$scope = 'public';
@@ -674,32 +665,17 @@ public static function getMemberProperties(File $phpcsFile, $stackPtr)
674665
case T_FINAL:
675666
$isFinal = true;
676667
break;
677-
}//end switch
678-
}//end for
668+
}
669+
}
679670

680-
$type = '';
681-
$typeToken = false;
682-
$typeEndToken = false;
683-
$nullableType = false;
671+
$type = '';
672+
$typeToken = false;
673+
$typeEndToken = false;
674+
$nullableType = false;
675+
$propertyTypeTokens = Collections::propertyTypeTokens();
684676

685677
if ($i < $stackPtr) {
686678
// We've found a type.
687-
$valid = [
688-
T_STRING => T_STRING,
689-
T_CALLABLE => T_CALLABLE,
690-
T_SELF => T_SELF,
691-
T_PARENT => T_PARENT,
692-
T_FALSE => T_FALSE,
693-
T_TRUE => T_TRUE,
694-
T_NULL => T_NULL,
695-
T_NAMESPACE => T_NAMESPACE,
696-
T_NS_SEPARATOR => T_NS_SEPARATOR,
697-
T_TYPE_UNION => T_TYPE_UNION,
698-
T_TYPE_INTERSECTION => T_TYPE_INTERSECTION,
699-
T_TYPE_OPEN_PARENTHESIS => T_TYPE_OPEN_PARENTHESIS,
700-
T_TYPE_CLOSE_PARENTHESIS => T_TYPE_CLOSE_PARENTHESIS,
701-
];
702-
703679
for ($i; $i < $stackPtr; $i++) {
704680
if ($tokens[$i]['code'] === T_VARIABLE) {
705681
// Hit another variable in a group definition.
@@ -710,7 +686,7 @@ public static function getMemberProperties(File $phpcsFile, $stackPtr)
710686
$nullableType = true;
711687
}
712688

713-
if (isset($valid[$tokens[$i]['code']]) === true) {
689+
if (isset($propertyTypeTokens[$tokens[$i]['code']]) === true) {
714690
$typeEndToken = $i;
715691
if ($typeToken === false) {
716692
$typeToken = $i;
@@ -723,7 +699,7 @@ public static function getMemberProperties(File $phpcsFile, $stackPtr)
723699
if ($type !== '' && $nullableType === true) {
724700
$type = '?' . $type;
725701
}
726-
}//end if
702+
}
727703

728704
return [
729705
'scope' => $scope,

Tests/BackCompat/BCFile/GetMemberPropertiesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,7 @@ public static function dataGetMemberProperties()
13561356
'is_readonly' => false,
13571357
'is_final' => true,
13581358
'type' => '(Foo&\Bar)|bool',
1359-
'type_token' => -9,
1359+
'type_token' => ($php8Names === true) ? -8 : -9,
13601360
'type_end_token' => -2,
13611361
'nullable_type' => false,
13621362
],

0 commit comments

Comments
 (0)