Convert array()/list() to short array `[]` with phpcbf
(Using short arrays for array destructuring requires php 7.1)
This commit is contained in:
Родитель
0b40640ac3
Коммит
5df29efbf9
12
src/Node.php
12
src/Node.php
|
@ -373,7 +373,7 @@ abstract class Node implements \JsonSerializable {
|
|||
}
|
||||
|
||||
protected function getChildrenKvPairs() {
|
||||
$result = array();
|
||||
$result = [];
|
||||
foreach ($this::CHILD_NAMES as $name) {
|
||||
$result[$name] = $this->$name;
|
||||
}
|
||||
|
@ -657,20 +657,20 @@ abstract class Node implements \JsonSerializable {
|
|||
// namespaces are case-insensitive
|
||||
// $alias = \strtolower($alias);
|
||||
$namespaceImportTable[$alias] = ResolvedName::buildName($namespaceNameParts, $contents);
|
||||
return array($namespaceImportTable, $functionImportTable, $constImportTable);
|
||||
return [$namespaceImportTable, $functionImportTable, $constImportTable];
|
||||
} elseif ($functionOrConst->kind === TokenKind::FunctionKeyword) {
|
||||
// functions are case-insensitive
|
||||
// $alias = \strtolower($alias);
|
||||
$functionImportTable[$alias] = ResolvedName::buildName($namespaceNameParts, $contents);
|
||||
return array($namespaceImportTable, $functionImportTable, $constImportTable);
|
||||
return [$namespaceImportTable, $functionImportTable, $constImportTable];
|
||||
} elseif ($functionOrConst->kind === TokenKind::ConstKeyword) {
|
||||
// constants are case-sensitive
|
||||
$constImportTable[$alias] = ResolvedName::buildName($namespaceNameParts, $contents);
|
||||
return array($namespaceImportTable, $functionImportTable, $constImportTable);
|
||||
return [$namespaceImportTable, $functionImportTable, $constImportTable];
|
||||
}
|
||||
return array($namespaceImportTable, $functionImportTable, $constImportTable);
|
||||
return [$namespaceImportTable, $functionImportTable, $constImportTable];
|
||||
}
|
||||
return array($namespaceImportTable, $functionImportTable, $constImportTable);
|
||||
return [$namespaceImportTable, $functionImportTable, $constImportTable];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -110,7 +110,7 @@ class QualifiedName extends Node implements NamespacedNameInterface {
|
|||
return $this->getNamespacedName();
|
||||
}
|
||||
|
||||
list($namespaceImportTable, $functionImportTable, $constImportTable) = $this->getImportTablesForCurrentScope();
|
||||
[$namespaceImportTable, $functionImportTable, $constImportTable] = $this->getImportTablesForCurrentScope();
|
||||
|
||||
// QUALIFIED NAMES
|
||||
// - first segment of the name is translated according to the current class/namespace import table.
|
||||
|
|
|
@ -179,7 +179,7 @@ class Parser {
|
|||
$this->sourceFile = $sourceFile;
|
||||
$sourceFile->fileContents = $fileContents;
|
||||
$sourceFile->uri = $uri;
|
||||
$sourceFile->statementList = array();
|
||||
$sourceFile->statementList = [];
|
||||
if ($this->getCurrentToken()->kind !== TokenKind::EndOfFileToken) {
|
||||
$inlineHTML = $this->parseInlineHtml($sourceFile);
|
||||
$sourceFile->statementList[] = $inlineHTML;
|
||||
|
@ -221,7 +221,7 @@ class Parser {
|
|||
$this->currentParseContext |= 1 << $listParseContext;
|
||||
$parseListElementFn = $this->getParseListElementFn($listParseContext);
|
||||
|
||||
$nodeArray = array();
|
||||
$nodeArray = [];
|
||||
while (!$this->isListTerminator($listParseContext)) {
|
||||
if ($this->isValidListElement($listParseContext, $this->getCurrentToken())) {
|
||||
$element = $parseListElementFn($parentNode);
|
||||
|
@ -1293,7 +1293,7 @@ class Parser {
|
|||
$expression = new StringLiteral();
|
||||
$expression->parent = $parentNode;
|
||||
$expression->startQuote = $this->eat(TokenKind::SingleQuoteToken, TokenKind::DoubleQuoteToken, TokenKind::HeredocStart, TokenKind::BacktickToken);
|
||||
$expression->children = array();
|
||||
$expression->children = [];
|
||||
|
||||
while (true) {
|
||||
switch ($this->getCurrentToken()->kind) {
|
||||
|
@ -1449,7 +1449,7 @@ class Parser {
|
|||
}
|
||||
|
||||
private function parseModifiers() {
|
||||
$modifiers = array();
|
||||
$modifiers = [];
|
||||
$token = $this->getCurrentToken();
|
||||
while ($this->isModifier($token)) {
|
||||
$modifiers[] = $token;
|
||||
|
@ -1963,12 +1963,12 @@ class Parser {
|
|||
private function parseBinaryExpressionOrHigher($precedence, $parentNode) {
|
||||
$leftOperand = $this->parseUnaryExpressionOrHigher($parentNode);
|
||||
|
||||
list($prevNewPrecedence, $prevAssociativity) = self::UNKNOWN_PRECEDENCE_AND_ASSOCIATIVITY;
|
||||
[$prevNewPrecedence, $prevAssociativity] = self::UNKNOWN_PRECEDENCE_AND_ASSOCIATIVITY;
|
||||
|
||||
while (true) {
|
||||
$token = $this->getCurrentToken();
|
||||
|
||||
list($newPrecedence, $associativity) = $this->getBinaryOperatorPrecedenceAndAssociativity($token);
|
||||
[$newPrecedence, $associativity] = $this->getBinaryOperatorPrecedenceAndAssociativity($token);
|
||||
|
||||
// Expressions using operators w/o associativity (equality, relational, instanceof)
|
||||
// cannot reference identical expression types within one of their operands.
|
||||
|
@ -2416,7 +2416,7 @@ class Parser {
|
|||
$tryStatement->tryKeyword = $this->eat1(TokenKind::TryKeyword);
|
||||
$tryStatement->compoundStatement = $this->parseCompoundStatement($tryStatement); // TODO verifiy this is only compound
|
||||
|
||||
$tryStatement->catchClauses = array(); // TODO - should be some standard for empty arrays vs. null?
|
||||
$tryStatement->catchClauses = []; // TODO - should be some standard for empty arrays vs. null?
|
||||
while ($this->checkToken(TokenKind::CatchKeyword)) {
|
||||
$tryStatement->catchClauses[] = $this->parseCatchClause($tryStatement);
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ class PhpTokenizer implements TokenStreamProviderInterface {
|
|||
|
||||
$tokens = static::tokenGetAll($content, $parseContext);
|
||||
|
||||
$arr = array();
|
||||
$arr = [];
|
||||
$fullStart = $start = $pos = $initialPos;
|
||||
if ($parseContext !== null) {
|
||||
// If needed, skip over the prefix we added for token_get_all and remove those tokens.
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace Microsoft\PhpParser;
|
|||
use Microsoft\PhpParser\TokenKind;
|
||||
|
||||
class TokenStringMaps {
|
||||
const KEYWORDS = array(
|
||||
const KEYWORDS = [
|
||||
"abstract" => TokenKind::AbstractKeyword,
|
||||
"and" => TokenKind::AndKeyword,
|
||||
"array" => TokenKind::ArrayKeyword,
|
||||
|
@ -82,7 +82,7 @@ class TokenStringMaps {
|
|||
|
||||
|
||||
// TODO soft reserved words?
|
||||
);
|
||||
];
|
||||
|
||||
const RESERVED_WORDS = [
|
||||
// http://php.net/manual/en/reserved.constants.php
|
||||
|
@ -109,7 +109,7 @@ class TokenStringMaps {
|
|||
"mixed" => TokenKind::MixedReservedWord,
|
||||
];
|
||||
|
||||
const OPERATORS_AND_PUNCTUATORS = array(
|
||||
const OPERATORS_AND_PUNCTUATORS = [
|
||||
"[" => TokenKind::OpenBracketToken,
|
||||
"]" => TokenKind::CloseBracketToken,
|
||||
"(" => TokenKind::OpenParenToken,
|
||||
|
@ -182,7 +182,7 @@ class TokenStringMaps {
|
|||
"?>\r" => TokenKind::ScriptSectionEndTag, // TODO, technically not an operator
|
||||
"@" => TokenKind::AtSymbolToken, // TODO not in spec
|
||||
"`" => TokenKind::BacktickToken
|
||||
);
|
||||
];
|
||||
|
||||
// TODO add new tokens
|
||||
}
|
||||
|
|
|
@ -10,13 +10,13 @@ use PHPUnit\Framework\TestCase;
|
|||
use Microsoft\PhpParser\TokenKind;
|
||||
|
||||
class LexerInvariantsTest extends TestCase {
|
||||
const FILENAMES = array(
|
||||
const FILENAMES = [
|
||||
__dir__ . "/cases/testfile.php",
|
||||
__dir__ . "/cases/commentsFile.php"
|
||||
);
|
||||
];
|
||||
|
||||
public static function tokensArrayProvider() {
|
||||
$fileToTokensMap = array();
|
||||
$fileToTokensMap = [];
|
||||
foreach (self::FILENAMES as $filename) {
|
||||
$lexer = \Microsoft\PhpParser\TokenStreamProviderFactory::GetTokenStreamProvider(file_get_contents($filename));
|
||||
$fileToTokensMap[basename($filename)] = [$filename, $lexer->getTokensArray()];
|
||||
|
|
|
@ -57,7 +57,7 @@ class LexicalGrammarTest extends TestCase {
|
|||
|
||||
$skipped = json_decode(file_get_contents(__DIR__ . "/skipped.json"));
|
||||
|
||||
$testProviderArray = array();
|
||||
$testProviderArray = [];
|
||||
foreach ($testCases as $testCase) {
|
||||
if (in_array(basename($testCase), $skipped)) {
|
||||
continue;
|
||||
|
@ -90,7 +90,7 @@ class LexicalGrammarTest extends TestCase {
|
|||
public function lexicalSpecProvider() {
|
||||
$testCases = glob(__dir__ . "/cases/php-langspec/**/*.php");
|
||||
|
||||
$testProviderArray = array();
|
||||
$testProviderArray = [];
|
||||
foreach ($testCases as $testCase) {
|
||||
$testProviderArray[basename($testCase)] = [$testCase, $testCase . ".tree"];
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ class ParserFrameworkValidationTests extends TestCase {
|
|||
$totalSize = 0;
|
||||
$frameworks = glob(__DIR__ . "/../validation/frameworks/*", GLOB_ONLYDIR);
|
||||
|
||||
$testProviderArray = array();
|
||||
$testProviderArray = [];
|
||||
foreach ($frameworks as $frameworkDir) {
|
||||
$frameworkName = basename($frameworkDir);
|
||||
$iterator = new RecursiveDirectoryIterator(__DIR__ . "/../validation/frameworks/" . $frameworkName);
|
||||
|
|
|
@ -88,7 +88,7 @@ class ParserGrammarTest extends TestCase {
|
|||
$testCases = glob(self::FILE_PATTERN . ".php");
|
||||
$skipped = json_decode(file_get_contents(__DIR__ . "/skipped.json"));
|
||||
|
||||
$testProviderArray = array();
|
||||
$testProviderArray = [];
|
||||
foreach ($testCases as $testCase) {
|
||||
if (in_array(basename($testCase), $skipped)) {
|
||||
continue;
|
||||
|
@ -124,7 +124,7 @@ class ParserGrammarTest extends TestCase {
|
|||
$testCases = glob(__DIR__ . "/cases/php-langspec/**/*.php");
|
||||
$skipped = json_decode(file_get_contents(__DIR__ . "/skipped.json"));
|
||||
|
||||
$testProviderArray = array();
|
||||
$testProviderArray = [];
|
||||
foreach ($testCases as $case) {
|
||||
if (in_array(basename($case), $skipped)) {
|
||||
continue;
|
||||
|
|
|
@ -13,7 +13,7 @@ class ParserInvariantsTest extends LexerInvariantsTest {
|
|||
const FILENAME_PATTERN = __dir__ . "/cases/{parser,parser74,}/*.php";
|
||||
|
||||
public static function sourceFileNodeProvider() {
|
||||
$testFiles = array();
|
||||
$testFiles = [];
|
||||
$testCases = glob(self::FILENAME_PATTERN, GLOB_BRACE);
|
||||
|
||||
foreach ($testCases as $filename) {
|
||||
|
@ -24,13 +24,13 @@ class ParserInvariantsTest extends LexerInvariantsTest {
|
|||
}
|
||||
|
||||
public static function tokensArrayProvider() {
|
||||
$testFiles = array();
|
||||
$testFiles = [];
|
||||
$testCases = glob(self::FILENAME_PATTERN, GLOB_BRACE);
|
||||
|
||||
foreach ($testCases as $filename) {
|
||||
$parser = new \Microsoft\PhpParser\Parser();
|
||||
$sourceFileNode = $parser->parseSourceFile(file_get_contents($filename));
|
||||
$tokensArray = array();
|
||||
$tokensArray = [];
|
||||
foreach ($sourceFileNode->getDescendantNodesAndTokens() as $child) {
|
||||
if ($child instanceof \Microsoft\PhpParser\Token) {
|
||||
$tokensArray[] = $child;
|
||||
|
|
Загрузка…
Ссылка в новой задаче