Skip to content

Commit 898791e

Browse files
Asymmetric visibility: expand tests, check is_array
1 parent cb00227 commit 898791e

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

src/Tokenizers/PHP.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,7 @@ protected function tokenize($string)
12341234
&& in_array($token[0], [T_PUBLIC, T_PROTECTED, T_PRIVATE], true) === true
12351235
&& ($stackPtr + 3) < $numTokens
12361236
&& $tokens[($stackPtr + 1)] === '('
1237+
&& is_array($tokens[($stackPtr + 2)])
12371238
&& $tokens[($stackPtr + 2)][0] === T_STRING
12381239
&& strtolower($tokens[($stackPtr + 2)][1]) === 'set'
12391240
&& $tokens[($stackPtr + 3)] === ')'

tests/Core/Tokenizers/PHP/BackfillAsymmetricVisibilityTest.inc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ class PropertyDemo {
1515
/* testPrivateSetPropertyUC */ PRIVATE(SET) mixed $priv2;
1616
public /* testPublicPrivateSetProperty */ private(set) mixed $priv3;
1717
public /* testPublicPrivateSetPropertyUC */ PRIVATE(SET) mixed $priv4;
18+
19+
/* testInvalidUnsetProperty */ public mixed $invalid1;
20+
/* testInvalidSpaceProperty */ public (set) mixed $invalid2;
21+
/* testInvalidCommentProperty */ protected/* foo */(set) mixed $invalid3;
22+
/* testInvalidGetProperty */ private(get) mixed $invalid4;
23+
/* testInvalidNoParenProperty */ private set mixed $invalid5;
1824
}
1925

2026
class ConstructorPromotionDemo {
@@ -33,5 +39,14 @@ class ConstructorPromotionDemo {
3339
/* testPrivateSetCPPUC */ PRIVATE(SET) mixed $priv2,
3440
public /* testPublicPrivateSetCPP */ private(set) mixed $priv3,
3541
public /* testPublicPrivateSetCPPUC */ PRIVATE(SET) mixed $priv4,
42+
43+
/* testInvalidUnsetCPP */ public(unset) mixed $invalid1,
44+
/* testInvalidSpaceCPP */ public (set) mixed $invalid2,
45+
/* testInvalidCommentCPP */ protected/* foo */(set) mixed $invalid3,
46+
/* testInvalidGetCPP */ private(get) mixed $invalid4,
47+
/* testInvalidNoParenCPP */ private set mixed $invalid5,
3648
) {}
3749
}
50+
51+
class LiveCodingDemo {
52+
/* testLiveCoding */ private(set

tests/Core/Tokenizers/PHP/BackfillAsymmetricVisibilityTest.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public function testAsymmetricVisibility($testMarker, $testType, $testContent)
3535
T_PUBLIC_SET,
3636
T_PROTECTED_SET,
3737
T_PRIVATE_SET,
38+
// For error cases
39+
constant($testType),
3840
],
3941
$testContent
4042
);
@@ -125,6 +127,31 @@ public static function dataAsymmetricVisibility()
125127
'testType' => 'T_PRIVATE_SET',
126128
'testContent' => 'PRIVATE(SET)',
127129
],
130+
'property, invalid case 1' => [
131+
'testMarker' => '/* testInvalidUnsetProperty */',
132+
'testType' => 'T_PUBLIC',
133+
'testContent' => 'public',
134+
],
135+
'property, invalid case 2' => [
136+
'testMarker' => '/* testInvalidSpaceProperty */',
137+
'testType' => 'T_PUBLIC',
138+
'testContent' => 'public',
139+
],
140+
'property, invalid case 3' => [
141+
'testMarker' => '/* testInvalidCommentProperty */',
142+
'testType' => 'T_PROTECTED',
143+
'testContent' => 'protected',
144+
],
145+
'property, invalid case 4' => [
146+
'testMarker' => '/* testInvalidGetProperty */',
147+
'testType' => 'T_PRIVATE',
148+
'testContent' => 'private',
149+
],
150+
'property, invalid case 5' => [
151+
'testMarker' => '/* testInvalidNoParenProperty */',
152+
'testType' => 'T_PRIVATE',
153+
'testContent' => 'private',
154+
],
128155

129156
// Constructor property promotion.
130157
'promotion, public set, no read visibility, lowercase' => [
@@ -187,6 +214,38 @@ public static function dataAsymmetricVisibility()
187214
'testType' => 'T_PRIVATE_SET',
188215
'testContent' => 'PRIVATE(SET)',
189216
],
217+
'promotion, invalid case 1' => [
218+
'testMarker' => '/* testInvalidUnsetCPP */',
219+
'testType' => 'T_PUBLIC',
220+
'testContent' => 'public',
221+
],
222+
'promotion, invalid case 2' => [
223+
'testMarker' => '/* testInvalidSpaceCPP */',
224+
'testType' => 'T_PUBLIC',
225+
'testContent' => 'public',
226+
],
227+
'promotion, invalid case 3' => [
228+
'testMarker' => '/* testInvalidCommentCPP */',
229+
'testType' => 'T_PROTECTED',
230+
'testContent' => 'protected',
231+
],
232+
'promotion, invalid case 4' => [
233+
'testMarker' => '/* testInvalidGetCPP */',
234+
'testType' => 'T_PRIVATE',
235+
'testContent' => 'private',
236+
],
237+
'promotion, invalid case 5' => [
238+
'testMarker' => '/* testInvalidNoParenCPP */',
239+
'testType' => 'T_PRIVATE',
240+
'testContent' => 'private',
241+
],
242+
243+
// Live coding.
244+
'live coding' => [
245+
'testMarker' => '/* testLiveCoding */',
246+
'testType' => 'T_PRIVATE',
247+
'testContent' => 'private',
248+
]
190249
];
191250

192251
}//end dataAsymmetricVisibility()

0 commit comments

Comments
 (0)