Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/Tokenizers/PHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -2688,13 +2688,18 @@ protected function processAdditional()
}

if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]) === false) {
if (isset($allowed[$this->tokens[$x]['code']]) === false) {
// Allow for control structures without braces.
if (($this->tokens[$x]['code'] === T_CLOSE_PARENTHESIS
&& isset($this->tokens[$x]['parenthesis_owner']) === true
&& isset(Util\Tokens::$scopeOpeners[$this->tokens[$this->tokens[$x]['parenthesis_owner']]['code']]) === true)
|| isset($allowed[$this->tokens[$x]['code']]) === false
) {
$isShortArray = true;
}

break;
}
}
}//end for

if ($isShortArray === true) {
$this->tokens[$i]['code'] = T_OPEN_SHORT_ARRAY;
Expand Down
14 changes: 14 additions & 0 deletions tests/Core/Tokenizer/ShortArrayTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ echo [1, 2, 3][0];
/* testArrayWithinFunctionCall */
$var = functionCall([$x, $y]);

if ( true ) {
/* testShortListDeclarationAfterBracedControlStructure */
[ $a ] = [ 'hi' ];
}

if ( true )
/* testShortListDeclarationAfterNonBracedControlStructure */
[ $a ] = [ 'hi' ];

if ( true ) :
/* testShortListDeclarationAfterAlternativeControlStructure */
[ $a ] = [ 'hi' ];
endif;

/* testLiveCoding */
// Intentional parse error. This has to be the last test in the file.
$array = [
63 changes: 33 additions & 30 deletions tests/Core/Tokenizer/ShortArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,29 @@ public function testSquareBrackets($testMarker)
public function dataSquareBrackets()
{
return [
['/* testArrayAccess1 */'],
['/* testArrayAccess2 */'],
['/* testArrayAssignment */'],
['/* testFunctionCallDereferencing */'],
['/* testMethodCallDereferencing */'],
['/* testStaticMethodCallDereferencing */'],
['/* testPropertyDereferencing */'],
['/* testPropertyDereferencingWithInaccessibleName */'],
['/* testStaticPropertyDereferencing */'],
['/* testStringDereferencing */'],
['/* testStringDereferencingDoubleQuoted */'],
['/* testConstantDereferencing */'],
['/* testClassConstantDereferencing */'],
['/* testMagicConstantDereferencing */'],
['/* testArrayAccessCurlyBraces */'],
['/* testArrayLiteralDereferencing */'],
['/* testShortArrayLiteralDereferencing */'],
['/* testClassMemberDereferencingOnInstantiation1 */'],
['/* testClassMemberDereferencingOnInstantiation2 */'],
['/* testClassMemberDereferencingOnClone */'],
['/* testNullsafeMethodCallDereferencing */'],
['/* testInterpolatedStringDereferencing */'],
['/* testLiveCoding */'],
'array access 1' => ['/* testArrayAccess1 */'],
'array access 2' => ['/* testArrayAccess2 */'],
'array assignment' => ['/* testArrayAssignment */'],
'function call dereferencing' => ['/* testFunctionCallDereferencing */'],
'method call dereferencing' => ['/* testMethodCallDereferencing */'],
'static method call dereferencing' => ['/* testStaticMethodCallDereferencing */'],
'property dereferencing' => ['/* testPropertyDereferencing */'],
'property dereferencing with inaccessable name' => ['/* testPropertyDereferencingWithInaccessibleName */'],
'static property dereferencing' => ['/* testStaticPropertyDereferencing */'],
'string dereferencing single quotes' => ['/* testStringDereferencing */'],
'string dereferencing double quotes' => ['/* testStringDereferencingDoubleQuoted */'],
'global constant dereferencing' => ['/* testConstantDereferencing */'],
'class constant dereferencing' => ['/* testClassConstantDereferencing */'],
'magic constant dereferencing' => ['/* testMagicConstantDereferencing */'],
'array access with curly braces' => ['/* testArrayAccessCurlyBraces */'],
'array literal dereferencing' => ['/* testArrayLiteralDereferencing */'],
'short array literal dereferencing' => ['/* testShortArrayLiteralDereferencing */'],
'class member dereferencing on instantiation 1' => ['/* testClassMemberDereferencingOnInstantiation1 */'],
'class member dereferencing on instantiation 2' => ['/* testClassMemberDereferencingOnInstantiation2 */'],
'class member dereferencing on clone' => ['/* testClassMemberDereferencingOnClone */'],
'nullsafe method call dereferencing' => ['/* testNullsafeMethodCallDereferencing */'],
'interpolated string dereferencing' => ['/* testInterpolatedStringDereferencing */'],
'live coding' => ['/* testLiveCoding */'],
];

}//end dataSquareBrackets()
Expand Down Expand Up @@ -117,13 +117,16 @@ public function testShortArrays($testMarker)
public function dataShortArrays()
{
return [
['/* testShortArrayDeclarationEmpty */'],
['/* testShortArrayDeclarationWithOneValue */'],
['/* testShortArrayDeclarationWithMultipleValues */'],
['/* testShortArrayDeclarationWithDereferencing */'],
['/* testShortListDeclaration */'],
['/* testNestedListDeclaration */'],
['/* testArrayWithinFunctionCall */'],
'short array empty' => ['/* testShortArrayDeclarationEmpty */'],
'short array with value' => ['/* testShortArrayDeclarationWithOneValue */'],
'short array with values' => ['/* testShortArrayDeclarationWithMultipleValues */'],
'short array with dereferencing' => ['/* testShortArrayDeclarationWithDereferencing */'],
'short list' => ['/* testShortListDeclaration */'],
'short list nested' => ['/* testNestedListDeclaration */'],
'short array within function call' => ['/* testArrayWithinFunctionCall */'],
'short list after braced control structure' => ['/* testShortListDeclarationAfterBracedControlStructure */'],
'short list after non-braced control structure' => ['/* testShortListDeclarationAfterNonBracedControlStructure */'],
'short list after alternative control structure' => ['/* testShortListDeclarationAfterAlternativeControlStructure */'],
];

}//end dataShortArrays()
Expand Down