Skip to content

Commit 760990b

Browse files
committed
Tokens::$functionNameTokens: include the parent keyword
Follow up to PR 3546, which changed how the `parent` keyword in a `new parent` snippet was tokenized from `T_STRING` to `T_PARENT`. The `T_PARENT` keyword token, however, was not included in the `Tokens::$functionNameTokens` array, which was the underlying cause for the bug reported in 3618. Fixed now. Tested by adding additional tests to the `Generic.WhiteSpace.ArbitraryParenthesesSpacing` sniff. These tests passed in PHPCS 3.6.2 and started failing in PHPCS 3.7.0. Once this fix has been merged, the tests will pass again.
1 parent 1359e17 commit 760990b

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

src/Standards/Generic/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,15 @@ $a = (
163163
if (true) {} ( 1+2) === 3 ? $a = 1 : $a = 2;
164164
class A {} ( 1+2) === 3 ? $a = 1 : $a = 2;
165165
function foo() {} ( 1+2) === 3 ? $a = 1 : $a = 2;
166+
167+
// Issue #3618.
168+
class NonArbitraryParenthesesWithKeywords {
169+
public static function baz( $foo, $bar ) {
170+
$a = new self();
171+
$b = new parent();
172+
$c = new static();
173+
174+
// self/static are already tested above, round line 45.
175+
$d = new parent( $foo,$bar );
176+
}
177+
}

src/Standards/Generic/Tests/WhiteSpace/ArbitraryParenthesesSpacingUnitTest.inc.fixed

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,15 @@ $a = (
151151
if (true) {} (1+2) === 3 ? $a = 1 : $a = 2;
152152
class A {} (1+2) === 3 ? $a = 1 : $a = 2;
153153
function foo() {} (1+2) === 3 ? $a = 1 : $a = 2;
154+
155+
// Issue #3618.
156+
class NonArbitraryParenthesesWithKeywords {
157+
public static function baz( $foo, $bar ) {
158+
$a = new self();
159+
$b = new parent();
160+
$c = new static();
161+
162+
// self/static are already tested above, round line 45.
163+
$d = new parent( $foo,$bar );
164+
}
165+
}

src/Util/Tokens.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,7 @@ final class Tokens
628628
T_UNSET => T_UNSET,
629629
T_EMPTY => T_EMPTY,
630630
T_SELF => T_SELF,
631+
T_PARENT => T_PARENT,
631632
T_STATIC => T_STATIC,
632633
];
633634

0 commit comments

Comments
 (0)