Skip to content

Commit 9015c61

Browse files
committed
switched array() to []
1 parent 554a59a commit 9015c61

File tree

9 files changed

+732
-732
lines changed

9 files changed

+732
-732
lines changed

Command/LintCommand.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
9191
throw new RuntimeException('Please provide a filename or pipe file content to STDIN.');
9292
}
9393

94-
return $this->display($io, array($this->validate($stdin, $flags)));
94+
return $this->display($io, [$this->validate($stdin, $flags)]);
9595
}
9696

9797
if (!$this->isReadable($filename)) {
9898
throw new RuntimeException(sprintf('File or directory "%s" is not readable.', $filename));
9999
}
100100

101-
$filesInfo = array();
101+
$filesInfo = [];
102102
foreach ($this->getFiles($filename) as $file) {
103103
$filesInfo[] = $this->validate(file_get_contents($file), $flags, $file);
104104
}
@@ -119,12 +119,12 @@ private function validate($content, $flags, $file = null)
119119
try {
120120
$this->getParser()->parse($content, Yaml::PARSE_CONSTANT | $flags);
121121
} catch (ParseException $e) {
122-
return array('file' => $file, 'line' => $e->getParsedLine(), 'valid' => false, 'message' => $e->getMessage());
122+
return ['file' => $file, 'line' => $e->getParsedLine(), 'valid' => false, 'message' => $e->getMessage()];
123123
} finally {
124124
restore_error_handler();
125125
}
126126

127-
return array('file' => $file, 'valid' => true);
127+
return ['file' => $file, 'valid' => true];
128128
}
129129

130130
private function display(SymfonyStyle $io, array $files)
@@ -188,7 +188,7 @@ private function getFiles($fileOrDirectory)
188188
}
189189

190190
foreach ($this->getDirectoryIterator($fileOrDirectory) as $file) {
191-
if (!\in_array($file->getExtension(), array('yml', 'yaml'))) {
191+
if (!\in_array($file->getExtension(), ['yml', 'yaml'])) {
192192
continue;
193193
}
194194

Escaper.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ class Escaper
2828
// first to ensure proper escaping because str_replace operates iteratively
2929
// on the input arrays. This ordering of the characters avoids the use of strtr,
3030
// which performs more slowly.
31-
private static $escapees = array('\\', '\\\\', '\\"', '"',
31+
private static $escapees = ['\\', '\\\\', '\\"', '"',
3232
"\x00", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07",
3333
"\x08", "\x09", "\x0a", "\x0b", "\x0c", "\x0d", "\x0e", "\x0f",
3434
"\x10", "\x11", "\x12", "\x13", "\x14", "\x15", "\x16", "\x17",
3535
"\x18", "\x19", "\x1a", "\x1b", "\x1c", "\x1d", "\x1e", "\x1f",
3636
"\xc2\x85", "\xc2\xa0", "\xe2\x80\xa8", "\xe2\x80\xa9",
37-
);
38-
private static $escaped = array('\\\\', '\\"', '\\\\', '\\"',
37+
];
38+
private static $escaped = ['\\\\', '\\"', '\\\\', '\\"',
3939
'\\0', '\\x01', '\\x02', '\\x03', '\\x04', '\\x05', '\\x06', '\\a',
4040
'\\b', '\\t', '\\n', '\\v', '\\f', '\\r', '\\x0e', '\\x0f',
4141
'\\x10', '\\x11', '\\x12', '\\x13', '\\x14', '\\x15', '\\x16', '\\x17',
4242
'\\x18', '\\x19', '\\x1a', '\\e', '\\x1c', '\\x1d', '\\x1e', '\\x1f',
4343
'\\N', '\\_', '\\L', '\\P',
44-
);
44+
];
4545

4646
/**
4747
* Determines if a PHP value would require double quoting in YAML.
@@ -78,7 +78,7 @@ public static function requiresSingleQuoting($value)
7878
{
7979
// Determines if a PHP value is entirely composed of a value that would
8080
// require single quoting in YAML.
81-
if (\in_array(strtolower($value), array('null', '~', 'true', 'false', 'y', 'n', 'yes', 'no', 'on', 'off'))) {
81+
if (\in_array(strtolower($value), ['null', '~', 'true', 'false', 'y', 'n', 'yes', 'no', 'on', 'off'])) {
8282
return true;
8383
}
8484

Inline.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static function initialize($flags, $parsedLineNumber = null, $parsedFilen
6363
*
6464
* @throws ParseException
6565
*/
66-
public static function parse($value, $flags = 0, $references = array())
66+
public static function parse($value, $flags = 0, $references = [])
6767
{
6868
if (\is_bool($flags)) {
6969
@trigger_error('Passing a boolean flag to toggle exception handling is deprecated since Symfony 3.1 and will be removed in 4.0. Use the Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED);
@@ -93,7 +93,7 @@ public static function parse($value, $flags = 0, $references = array())
9393
if (\func_num_args() >= 5) {
9494
$references = func_get_arg(4);
9595
} else {
96-
$references = array();
96+
$references = [];
9797
}
9898
}
9999

@@ -285,7 +285,7 @@ private static function dumpArray($value, $flags)
285285
{
286286
// array
287287
if (($value || Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE & $flags) && !self::isHash($value)) {
288-
$output = array();
288+
$output = [];
289289
foreach ($value as $val) {
290290
$output[] = self::dump($val, $flags);
291291
}
@@ -294,7 +294,7 @@ private static function dumpArray($value, $flags)
294294
}
295295

296296
// hash
297-
$output = array();
297+
$output = [];
298298
foreach ($value as $key => $val) {
299299
$output[] = sprintf('%s: %s', self::dump($key, $flags), self::dump($val, $flags));
300300
}
@@ -318,9 +318,9 @@ private static function dumpArray($value, $flags)
318318
*
319319
* @internal
320320
*/
321-
public static function parseScalar($scalar, $flags = 0, $delimiters = null, &$i = 0, $evaluate = true, $references = array(), $legacyOmittedKeySupport = false)
321+
public static function parseScalar($scalar, $flags = 0, $delimiters = null, &$i = 0, $evaluate = true, $references = [], $legacyOmittedKeySupport = false)
322322
{
323-
if (\in_array($scalar[$i], array('"', "'"))) {
323+
if (\in_array($scalar[$i], ['"', "'"])) {
324324
// quoted scalar
325325
$output = self::parseQuotedScalar($scalar, $i);
326326

@@ -409,9 +409,9 @@ private static function parseQuotedScalar($scalar, &$i)
409409
*
410410
* @throws ParseException When malformed inline YAML string is parsed
411411
*/
412-
private static function parseSequence($sequence, $flags, &$i = 0, $references = array())
412+
private static function parseSequence($sequence, $flags, &$i = 0, $references = [])
413413
{
414-
$output = array();
414+
$output = [];
415415
$len = \strlen($sequence);
416416
++$i;
417417

@@ -437,8 +437,8 @@ private static function parseSequence($sequence, $flags, &$i = 0, $references =
437437
$value = self::parseMapping($sequence, $flags, $i, $references);
438438
break;
439439
default:
440-
$isQuoted = \in_array($sequence[$i], array('"', "'"));
441-
$value = self::parseScalar($sequence, $flags, array(',', ']'), $i, null === $tag, $references);
440+
$isQuoted = \in_array($sequence[$i], ['"', "'"]);
441+
$value = self::parseScalar($sequence, $flags, [',', ']'], $i, null === $tag, $references);
442442

443443
// the value can be an array if a reference has been resolved to an array var
444444
if (\is_string($value) && !$isQuoted && false !== strpos($value, ': ')) {
@@ -478,9 +478,9 @@ private static function parseSequence($sequence, $flags, &$i = 0, $references =
478478
*
479479
* @throws ParseException When malformed inline YAML string is parsed
480480
*/
481-
private static function parseMapping($mapping, $flags, &$i = 0, $references = array())
481+
private static function parseMapping($mapping, $flags, &$i = 0, $references = [])
482482
{
483-
$output = array();
483+
$output = [];
484484
$len = \strlen($mapping);
485485
++$i;
486486
$allowOverwrite = false;
@@ -501,8 +501,8 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
501501
}
502502

503503
// key
504-
$isKeyQuoted = \in_array($mapping[$i], array('"', "'"), true);
505-
$key = self::parseScalar($mapping, $flags, array(':', ' '), $i, false, array(), true);
504+
$isKeyQuoted = \in_array($mapping[$i], ['"', "'"], true);
505+
$key = self::parseScalar($mapping, $flags, [':', ' '], $i, false, [], true);
506506

507507
if (':' !== $key && false === $i = strpos($mapping, ':', $i)) {
508508
break;
@@ -520,7 +520,7 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
520520
}
521521
}
522522

523-
if (':' !== $key && !$isKeyQuoted && (!isset($mapping[$i + 1]) || !\in_array($mapping[$i + 1], array(' ', ',', '[', ']', '{', '}'), true))) {
523+
if (':' !== $key && !$isKeyQuoted && (!isset($mapping[$i + 1]) || !\in_array($mapping[$i + 1], [' ', ',', '[', ']', '{', '}'], true))) {
524524
@trigger_error(self::getDeprecationMessage('Using a colon after an unquoted mapping key that is not followed by an indication character (i.e. " ", ",", "[", "]", "{", "}") is deprecated since Symfony 3.2 and will throw a ParseException in 4.0.'), E_USER_DEPRECATED);
525525
}
526526

@@ -578,7 +578,7 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
578578
}
579579
break;
580580
default:
581-
$value = self::parseScalar($mapping, $flags, array(',', '}'), $i, null === $tag, $references);
581+
$value = self::parseScalar($mapping, $flags, [',', '}'], $i, null === $tag, $references);
582582
// Spec: Keys MUST be unique; first one wins.
583583
// Parser cannot abort this mapping earlier, since lines
584584
// are processed sequentially.
@@ -616,7 +616,7 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
616616
*
617617
* @throws ParseException when object parsing support was disabled and the parser detected a PHP object or when a reference could not be resolved
618618
*/
619-
private static function evaluateScalar($scalar, $flags, $references = array())
619+
private static function evaluateScalar($scalar, $flags, $references = [])
620620
{
621621
$scalar = trim($scalar);
622622
$scalarLower = strtolower($scalar);
@@ -766,7 +766,7 @@ private static function evaluateScalar($scalar, $flags, $references = array())
766766
@trigger_error(self::getDeprecationMessage('Using the comma as a group separator for floats is deprecated since Symfony 3.2 and will be removed in 4.0.'), E_USER_DEPRECATED);
767767
}
768768

769-
return (float) str_replace(array(',', '_'), '', $scalar);
769+
return (float) str_replace([',', '_'], '', $scalar);
770770
case Parser::preg_match(self::getTimestampRegex(), $scalar):
771771
if (Yaml::PARSE_DATETIME & $flags) {
772772
// When no timezone is provided in the parsed date, YAML spec says we must assume UTC.
@@ -805,7 +805,7 @@ private static function parseTag($value, &$i, $flags)
805805
$nextOffset += strspn($value, ' ', $nextOffset);
806806

807807
// Is followed by a scalar
808-
if ((!isset($value[$nextOffset]) || !\in_array($value[$nextOffset], array('[', '{'), true)) && 'tagged' !== $tag) {
808+
if ((!isset($value[$nextOffset]) || !\in_array($value[$nextOffset], ['[', '{'], true)) && 'tagged' !== $tag) {
809809
// Manage non-whitelisted scalars in {@link self::evaluateScalar()}
810810
return;
811811
}

Parser.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ class Parser
2929
private $filename;
3030
private $offset = 0;
3131
private $totalNumberOfLines;
32-
private $lines = array();
32+
private $lines = [];
3333
private $currentLineNb = -1;
3434
private $currentLine = '';
35-
private $refs = array();
36-
private $skippedLineNumbers = array();
37-
private $locallySkippedLineNumbers = array();
38-
private $refsBeingParsed = array();
35+
private $refs = [];
36+
private $skippedLineNumbers = [];
37+
private $locallySkippedLineNumbers = [];
38+
private $refsBeingParsed = [];
3939

4040
public function __construct()
4141
{
@@ -127,7 +127,7 @@ public function parse($value, $flags = 0)
127127
throw new ParseException('The YAML value does not appear to be valid UTF-8.', -1, null, $this->filename);
128128
}
129129

130-
$this->refs = array();
130+
$this->refs = [];
131131

132132
$mbEncoding = null;
133133
$e = null;
@@ -148,11 +148,11 @@ public function parse($value, $flags = 0)
148148
mb_internal_encoding($mbEncoding);
149149
}
150150

151-
$this->lines = array();
151+
$this->lines = [];
152152
$this->currentLine = '';
153-
$this->refs = array();
154-
$this->skippedLineNumbers = array();
155-
$this->locallySkippedLineNumbers = array();
153+
$this->refs = [];
154+
$this->skippedLineNumbers = [];
155+
$this->locallySkippedLineNumbers = [];
156156

157157
if (null !== $e) {
158158
throw $e;
@@ -167,7 +167,7 @@ private function doParse($value, $flags)
167167
$this->currentLine = '';
168168
$value = $this->cleanup($value);
169169
$this->lines = explode("\n", $value);
170-
$this->locallySkippedLineNumbers = array();
170+
$this->locallySkippedLineNumbers = [];
171171

172172
if (null === $this->totalNumberOfLines) {
173173
$this->totalNumberOfLines = \count($this->lines);
@@ -177,7 +177,7 @@ private function doParse($value, $flags)
177177
return null;
178178
}
179179

180-
$data = array();
180+
$data = [];
181181
$context = null;
182182
$allowOverwrite = false;
183183

@@ -250,7 +250,7 @@ private function doParse($value, $flags)
250250
}
251251
} elseif (
252252
self::preg_match('#^(?P<key>(?:![^\s]++\s++)?(?:'.Inline::REGEX_QUOTED_STRING.'|(?:!?!php/const:)?[^ \'"\[\{!].*?)) *\:(\s++(?P<value>.+))?$#u', rtrim($this->currentLine), $values)
253-
&& (false === strpos($values['key'], ' #') || \in_array($values['key'][0], array('"', "'")))
253+
&& (false === strpos($values['key'], ' #') || \in_array($values['key'][0], ['"', "'"]))
254254
) {
255255
if ($context && 'sequence' == $context) {
256256
throw new ParseException('You cannot define a mapping item when in a sequence', $this->currentLineNb + 1, $this->currentLine, $this->filename);
@@ -596,7 +596,7 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)
596596
$newIndent = $indentation;
597597
}
598598

599-
$data = array();
599+
$data = [];
600600
if ($this->getCurrentLineIndentation() >= $newIndent) {
601601
$data[] = substr($this->currentLine, $newIndent);
602602
} elseif ($this->isCurrentLineEmpty() || $this->isCurrentLineComment()) {
@@ -735,7 +735,7 @@ private function parseValue($value, $flags, $context)
735735
return Inline::parse($value, $flags, $this->refs);
736736
}
737737

738-
$lines = array();
738+
$lines = [];
739739

740740
while ($this->moveToNextLine()) {
741741
// unquoted strings end before the first unindented line
@@ -800,7 +800,7 @@ private function parseBlockScalar($style, $chomping = '', $indentation = 0)
800800
}
801801

802802
$isCurrentLineBlank = $this->isCurrentLineBlank();
803-
$blockLines = array();
803+
$blockLines = [];
804804

805805
// leading blank lines are consumed before determining indentation
806806
while ($notEOF && $isCurrentLineBlank) {
@@ -972,7 +972,7 @@ private function isCurrentLineLastLineInDocument()
972972
*/
973973
private function cleanup($value)
974974
{
975-
$value = str_replace(array("\r\n", "\r"), "\n", $value);
975+
$value = str_replace(["\r\n", "\r"], "\n", $value);
976976

977977
// strip YAML header
978978
$count = 0;

Tests/Command/LintCommandTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testLintCorrectFile()
3131
$tester = $this->createCommandTester();
3232
$filename = $this->createFile('foo: bar');
3333

34-
$ret = $tester->execute(array('filename' => $filename), array('verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false));
34+
$ret = $tester->execute(['filename' => $filename], ['verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false]);
3535

3636
$this->assertEquals(0, $ret, 'Returns 0 in case of success');
3737
$this->assertRegExp('/^\/\/ OK in /', trim($tester->getDisplay()));
@@ -45,7 +45,7 @@ public function testLintIncorrectFile()
4545
$tester = $this->createCommandTester();
4646
$filename = $this->createFile($incorrectContent);
4747

48-
$ret = $tester->execute(array('filename' => $filename), array('decorated' => false));
48+
$ret = $tester->execute(['filename' => $filename], ['decorated' => false]);
4949

5050
$this->assertEquals(1, $ret, 'Returns 1 in case of error');
5151
$this->assertContains('Unable to parse at line 3 (near "bar").', trim($tester->getDisplay()));
@@ -56,7 +56,7 @@ public function testConstantAsKey()
5656
$yaml = <<<YAML
5757
!php/const 'Symfony\Component\Yaml\Tests\Command\Foo::TEST': bar
5858
YAML;
59-
$ret = $this->createCommandTester()->execute(array('filename' => $this->createFile($yaml)), array('verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false));
59+
$ret = $this->createCommandTester()->execute(['filename' => $this->createFile($yaml)], ['verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false]);
6060
$this->assertSame(0, $ret, 'lint:yaml exits with code 0 in case of success');
6161
}
6262

@@ -65,7 +65,7 @@ public function testCustomTags()
6565
$yaml = <<<YAML
6666
foo: !my_tag {foo: bar}
6767
YAML;
68-
$ret = $this->createCommandTester()->execute(array('filename' => $this->createFile($yaml), '--parse-tags' => true), array('verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false));
68+
$ret = $this->createCommandTester()->execute(['filename' => $this->createFile($yaml), '--parse-tags' => true], ['verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false]);
6969
$this->assertSame(0, $ret, 'lint:yaml exits with code 0 in case of success');
7070
}
7171

@@ -74,7 +74,7 @@ public function testCustomTagsError()
7474
$yaml = <<<YAML
7575
foo: !my_tag {foo: bar}
7676
YAML;
77-
$ret = $this->createCommandTester()->execute(array('filename' => $this->createFile($yaml)), array('verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false));
77+
$ret = $this->createCommandTester()->execute(['filename' => $this->createFile($yaml)], ['verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false]);
7878
$this->assertSame(1, $ret, 'lint:yaml exits with code 1 in case of error');
7979
}
8080

@@ -87,7 +87,7 @@ public function testLintFileNotReadable()
8787
$filename = $this->createFile('');
8888
unlink($filename);
8989

90-
$ret = $tester->execute(array('filename' => $filename), array('decorated' => false));
90+
$ret = $tester->execute(['filename' => $filename], ['decorated' => false]);
9191
}
9292

9393
/**
@@ -117,7 +117,7 @@ protected function createCommandTester()
117117

118118
protected function setUp()
119119
{
120-
$this->files = array();
120+
$this->files = [];
121121
@mkdir(sys_get_temp_dir().'/framework-yml-lint-test');
122122
}
123123

0 commit comments

Comments
 (0)