Skip to content

Commit 5df29ef

Browse files
committed
Convert array()/list() to short array [] with phpcbf
(Using short arrays for array destructuring requires php 7.1)
1 parent 0b40640 commit 5df29ef

10 files changed

+30
-30
lines changed

src/Node.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ public function getLeadingCommentAndWhitespaceText() : string {
373373
}
374374

375375
protected function getChildrenKvPairs() {
376-
$result = array();
376+
$result = [];
377377
foreach ($this::CHILD_NAMES as $name) {
378378
$result[$name] = $this->$name;
379379
}
@@ -657,20 +657,20 @@ private function addToImportTable($alias, $functionOrConst, $namespaceNameParts,
657657
// namespaces are case-insensitive
658658
// $alias = \strtolower($alias);
659659
$namespaceImportTable[$alias] = ResolvedName::buildName($namespaceNameParts, $contents);
660-
return array($namespaceImportTable, $functionImportTable, $constImportTable);
660+
return [$namespaceImportTable, $functionImportTable, $constImportTable];
661661
} elseif ($functionOrConst->kind === TokenKind::FunctionKeyword) {
662662
// functions are case-insensitive
663663
// $alias = \strtolower($alias);
664664
$functionImportTable[$alias] = ResolvedName::buildName($namespaceNameParts, $contents);
665-
return array($namespaceImportTable, $functionImportTable, $constImportTable);
665+
return [$namespaceImportTable, $functionImportTable, $constImportTable];
666666
} elseif ($functionOrConst->kind === TokenKind::ConstKeyword) {
667667
// constants are case-sensitive
668668
$constImportTable[$alias] = ResolvedName::buildName($namespaceNameParts, $contents);
669-
return array($namespaceImportTable, $functionImportTable, $constImportTable);
669+
return [$namespaceImportTable, $functionImportTable, $constImportTable];
670670
}
671-
return array($namespaceImportTable, $functionImportTable, $constImportTable);
671+
return [$namespaceImportTable, $functionImportTable, $constImportTable];
672672
}
673-
return array($namespaceImportTable, $functionImportTable, $constImportTable);
673+
return [$namespaceImportTable, $functionImportTable, $constImportTable];
674674
}
675675

676676
/**

src/Node/QualifiedName.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function getResolvedName($namespaceDefinition = null) {
110110
return $this->getNamespacedName();
111111
}
112112

113-
list($namespaceImportTable, $functionImportTable, $constImportTable) = $this->getImportTablesForCurrentScope();
113+
[$namespaceImportTable, $functionImportTable, $constImportTable] = $this->getImportTablesForCurrentScope();
114114

115115
// QUALIFIED NAMES
116116
// - first segment of the name is translated according to the current class/namespace import table.

src/Parser.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public function parseSourceFile(string $fileContents, string $uri = null) : Sour
179179
$this->sourceFile = $sourceFile;
180180
$sourceFile->fileContents = $fileContents;
181181
$sourceFile->uri = $uri;
182-
$sourceFile->statementList = array();
182+
$sourceFile->statementList = [];
183183
if ($this->getCurrentToken()->kind !== TokenKind::EndOfFileToken) {
184184
$inlineHTML = $this->parseInlineHtml($sourceFile);
185185
$sourceFile->statementList[] = $inlineHTML;
@@ -221,7 +221,7 @@ private function parseList($parentNode, int $listParseContext) {
221221
$this->currentParseContext |= 1 << $listParseContext;
222222
$parseListElementFn = $this->getParseListElementFn($listParseContext);
223223

224-
$nodeArray = array();
224+
$nodeArray = [];
225225
while (!$this->isListTerminator($listParseContext)) {
226226
if ($this->isValidListElement($listParseContext, $this->getCurrentToken())) {
227227
$element = $parseListElementFn($parentNode);
@@ -1293,7 +1293,7 @@ private function parseStringLiteralExpression2($parentNode) {
12931293
$expression = new StringLiteral();
12941294
$expression->parent = $parentNode;
12951295
$expression->startQuote = $this->eat(TokenKind::SingleQuoteToken, TokenKind::DoubleQuoteToken, TokenKind::HeredocStart, TokenKind::BacktickToken);
1296-
$expression->children = array();
1296+
$expression->children = [];
12971297

12981298
while (true) {
12991299
switch ($this->getCurrentToken()->kind) {
@@ -1449,7 +1449,7 @@ private function isModifier($token) {
14491449
}
14501450

14511451
private function parseModifiers() {
1452-
$modifiers = array();
1452+
$modifiers = [];
14531453
$token = $this->getCurrentToken();
14541454
while ($this->isModifier($token)) {
14551455
$modifiers[] = $token;
@@ -1963,12 +1963,12 @@ private function parseUnaryExpressionOrHigher($parentNode) {
19631963
private function parseBinaryExpressionOrHigher($precedence, $parentNode) {
19641964
$leftOperand = $this->parseUnaryExpressionOrHigher($parentNode);
19651965

1966-
list($prevNewPrecedence, $prevAssociativity) = self::UNKNOWN_PRECEDENCE_AND_ASSOCIATIVITY;
1966+
[$prevNewPrecedence, $prevAssociativity] = self::UNKNOWN_PRECEDENCE_AND_ASSOCIATIVITY;
19671967

19681968
while (true) {
19691969
$token = $this->getCurrentToken();
19701970

1971-
list($newPrecedence, $associativity) = $this->getBinaryOperatorPrecedenceAndAssociativity($token);
1971+
[$newPrecedence, $associativity] = $this->getBinaryOperatorPrecedenceAndAssociativity($token);
19721972

19731973
// Expressions using operators w/o associativity (equality, relational, instanceof)
19741974
// cannot reference identical expression types within one of their operands.
@@ -2416,7 +2416,7 @@ private function parseTryStatement($parentNode) {
24162416
$tryStatement->tryKeyword = $this->eat1(TokenKind::TryKeyword);
24172417
$tryStatement->compoundStatement = $this->parseCompoundStatement($tryStatement); // TODO verifiy this is only compound
24182418

2419-
$tryStatement->catchClauses = array(); // TODO - should be some standard for empty arrays vs. null?
2419+
$tryStatement->catchClauses = []; // TODO - should be some standard for empty arrays vs. null?
24202420
while ($this->checkToken(TokenKind::CatchKeyword)) {
24212421
$tryStatement->catchClauses[] = $this->parseCatchClause($tryStatement);
24222422
}

src/PhpTokenizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static function getTokensArrayFromContent(
8282

8383
$tokens = static::tokenGetAll($content, $parseContext);
8484

85-
$arr = array();
85+
$arr = [];
8686
$fullStart = $start = $pos = $initialPos;
8787
if ($parseContext !== null) {
8888
// If needed, skip over the prefix we added for token_get_all and remove those tokens.

src/TokenStringMaps.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Microsoft\PhpParser\TokenKind;
1010

1111
class TokenStringMaps {
12-
const KEYWORDS = array(
12+
const KEYWORDS = [
1313
"abstract" => TokenKind::AbstractKeyword,
1414
"and" => TokenKind::AndKeyword,
1515
"array" => TokenKind::ArrayKeyword,
@@ -82,7 +82,7 @@ class TokenStringMaps {
8282

8383

8484
// TODO soft reserved words?
85-
);
85+
];
8686

8787
const RESERVED_WORDS = [
8888
// http://php.net/manual/en/reserved.constants.php
@@ -109,7 +109,7 @@ class TokenStringMaps {
109109
"mixed" => TokenKind::MixedReservedWord,
110110
];
111111

112-
const OPERATORS_AND_PUNCTUATORS = array(
112+
const OPERATORS_AND_PUNCTUATORS = [
113113
"[" => TokenKind::OpenBracketToken,
114114
"]" => TokenKind::CloseBracketToken,
115115
"(" => TokenKind::OpenParenToken,
@@ -182,7 +182,7 @@ class TokenStringMaps {
182182
"?>\r" => TokenKind::ScriptSectionEndTag, // TODO, technically not an operator
183183
"@" => TokenKind::AtSymbolToken, // TODO not in spec
184184
"`" => TokenKind::BacktickToken
185-
);
185+
];
186186

187187
// TODO add new tokens
188188
}

tests/LexerInvariantsTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
use Microsoft\PhpParser\TokenKind;
1111

1212
class LexerInvariantsTest extends TestCase {
13-
const FILENAMES = array(
13+
const FILENAMES = [
1414
__dir__ . "/cases/testfile.php",
1515
__dir__ . "/cases/commentsFile.php"
16-
);
16+
];
1717

1818
public static function tokensArrayProvider() {
19-
$fileToTokensMap = array();
19+
$fileToTokensMap = [];
2020
foreach (self::FILENAMES as $filename) {
2121
$lexer = \Microsoft\PhpParser\TokenStreamProviderFactory::GetTokenStreamProvider(file_get_contents($filename));
2222
$fileToTokensMap[basename($filename)] = [$filename, $lexer->getTokensArray()];

tests/LexicalGrammarTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function lexicalProvider() {
5757

5858
$skipped = json_decode(file_get_contents(__DIR__ . "/skipped.json"));
5959

60-
$testProviderArray = array();
60+
$testProviderArray = [];
6161
foreach ($testCases as $testCase) {
6262
if (in_array(basename($testCase), $skipped)) {
6363
continue;
@@ -90,7 +90,7 @@ public function testSpecTokenClassificationAndLength($testCaseFile, $expectedTok
9090
public function lexicalSpecProvider() {
9191
$testCases = glob(__dir__ . "/cases/php-langspec/**/*.php");
9292

93-
$testProviderArray = array();
93+
$testProviderArray = [];
9494
foreach ($testCases as $testCase) {
9595
$testProviderArray[basename($testCase)] = [$testCase, $testCase . ".tree"];
9696
}

tests/ParserFrameworkValidationTests.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function frameworkErrorProvider() {
1212
$totalSize = 0;
1313
$frameworks = glob(__DIR__ . "/../validation/frameworks/*", GLOB_ONLYDIR);
1414

15-
$testProviderArray = array();
15+
$testProviderArray = [];
1616
foreach ($frameworks as $frameworkDir) {
1717
$frameworkName = basename($frameworkDir);
1818
$iterator = new RecursiveDirectoryIterator(__DIR__ . "/../validation/frameworks/" . $frameworkName);

tests/ParserGrammarTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function treeProvider() {
8888
$testCases = glob(self::FILE_PATTERN . ".php");
8989
$skipped = json_decode(file_get_contents(__DIR__ . "/skipped.json"));
9090

91-
$testProviderArray = array();
91+
$testProviderArray = [];
9292
foreach ($testCases as $testCase) {
9393
if (in_array(basename($testCase), $skipped)) {
9494
continue;
@@ -124,7 +124,7 @@ public function outTreeProvider() {
124124
$testCases = glob(__DIR__ . "/cases/php-langspec/**/*.php");
125125
$skipped = json_decode(file_get_contents(__DIR__ . "/skipped.json"));
126126

127-
$testProviderArray = array();
127+
$testProviderArray = [];
128128
foreach ($testCases as $case) {
129129
if (in_array(basename($case), $skipped)) {
130130
continue;

tests/ParserInvariantsTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ParserInvariantsTest extends LexerInvariantsTest {
1313
const FILENAME_PATTERN = __dir__ . "/cases/{parser,parser74,}/*.php";
1414

1515
public static function sourceFileNodeProvider() {
16-
$testFiles = array();
16+
$testFiles = [];
1717
$testCases = glob(self::FILENAME_PATTERN, GLOB_BRACE);
1818

1919
foreach ($testCases as $filename) {
@@ -24,13 +24,13 @@ public static function sourceFileNodeProvider() {
2424
}
2525

2626
public static function tokensArrayProvider() {
27-
$testFiles = array();
27+
$testFiles = [];
2828
$testCases = glob(self::FILENAME_PATTERN, GLOB_BRACE);
2929

3030
foreach ($testCases as $filename) {
3131
$parser = new \Microsoft\PhpParser\Parser();
3232
$sourceFileNode = $parser->parseSourceFile(file_get_contents($filename));
33-
$tokensArray = array();
33+
$tokensArray = [];
3434
foreach ($sourceFileNode->getDescendantNodesAndTokens() as $child) {
3535
if ($child instanceof \Microsoft\PhpParser\Token) {
3636
$tokensArray[] = $child;

0 commit comments

Comments
 (0)