Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: symfony/yaml
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v4.1.10
Choose a base ref
...
head repository: symfony/yaml
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v4.1.11
Choose a head ref
  • 5 commits
  • 31 files changed
  • 1 contributor

Commits on Jan 16, 2019

  1. switched array() to []

    fabpot committed Jan 16, 2019
    Copy the full SHA
    9015c61 View commit details
  2. fixed CS on YAML fixtures

    fabpot committed Jan 16, 2019
    Copy the full SHA
    ba11776 View commit details
  3. Merge branch '3.4' into 4.1

    * 3.4:
      fixed CS
      fixed short array CS in comments
      fixed CS in ExpressionLanguage fixtures
      fixed CS in generated files
      fixed CS on generated container files
      fixed CS on Form PHP templates
      fixed CS on YAML fixtures
      fixed fixtures
      switched array() to []
    fabpot committed Jan 16, 2019
    Copy the full SHA
    b5794d3 View commit details
  4. fixed CS

    fabpot committed Jan 16, 2019
    Copy the full SHA
    ed61766 View commit details
  5. fixed CS

    fabpot committed Jan 16, 2019
    Copy the full SHA
    874d921 View commit details
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -143,7 +143,7 @@ CHANGELOG
* Added support for customizing the dumped YAML string through an optional bit field:

```php
Yaml::dump(array('foo' => new A(), 'bar' => 1), 0, 0, Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE | Yaml::DUMP_OBJECT);
Yaml::dump(['foo' => new A(), 'bar' => 1], 0, 0, Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE | Yaml::DUMP_OBJECT);
```

3.0.0
10 changes: 5 additions & 5 deletions Command/LintCommand.php
Original file line number Diff line number Diff line change
@@ -91,14 +91,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
throw new RuntimeException('Please provide a filename or pipe file content to STDIN.');
}

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

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

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

return array('file' => $file, 'valid' => true);
return ['file' => $file, 'valid' => true];
}

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

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

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

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

36 changes: 18 additions & 18 deletions Inline.php
Original file line number Diff line number Diff line change
@@ -63,7 +63,7 @@ public static function initialize($flags, $parsedLineNumber = null, $parsedFilen
*
* @throws ParseException
*/
public static function parse(string $value = null, int $flags = 0, array $references = array())
public static function parse(string $value = null, int $flags = 0, array $references = [])
{
self::initialize($flags);

@@ -142,7 +142,7 @@ public static function dump($value, int $flags = 0): string
}

if (Yaml::DUMP_OBJECT_AS_MAP & $flags && ($value instanceof \stdClass || $value instanceof \ArrayObject)) {
$output = array();
$output = [];

foreach ($value as $key => $val) {
$output[] = sprintf('%s: %s', self::dump($key, $flags), self::dump($val, $flags));
@@ -239,7 +239,7 @@ private static function dumpArray(array $value, int $flags): string
{
// array
if (($value || Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE & $flags) && !self::isHash($value)) {
$output = array();
$output = [];
foreach ($value as $val) {
$output[] = self::dump($val, $flags);
}
@@ -248,7 +248,7 @@ private static function dumpArray(array $value, int $flags): string
}

// hash
$output = array();
$output = [];
foreach ($value as $key => $val) {
$output[] = sprintf('%s: %s', self::dump($key, $flags), self::dump($val, $flags));
}
@@ -263,9 +263,9 @@ private static function dumpArray(array $value, int $flags): string
*
* @throws ParseException When malformed inline YAML string is parsed
*/
public static function parseScalar(string $scalar, int $flags = 0, array $delimiters = null, int &$i = 0, bool $evaluate = true, array $references = array())
public static function parseScalar(string $scalar, int $flags = 0, array $delimiters = null, int &$i = 0, bool $evaluate = true, array $references = [])
{
if (\in_array($scalar[$i], array('"', "'"))) {
if (\in_array($scalar[$i], ['"', "'"])) {
// quoted scalar
$output = self::parseQuotedScalar($scalar, $i);

@@ -339,9 +339,9 @@ private static function parseQuotedScalar(string $scalar, int &$i): string
*
* @throws ParseException When malformed inline YAML string is parsed
*/
private static function parseSequence(string $sequence, int $flags, int &$i = 0, array $references = array()): array
private static function parseSequence(string $sequence, int $flags, int &$i = 0, array $references = []): array
{
$output = array();
$output = [];
$len = \strlen($sequence);
++$i;

@@ -367,8 +367,8 @@ private static function parseSequence(string $sequence, int $flags, int &$i = 0,
$value = self::parseMapping($sequence, $flags, $i, $references);
break;
default:
$isQuoted = \in_array($sequence[$i], array('"', "'"));
$value = self::parseScalar($sequence, $flags, array(',', ']'), $i, null === $tag, $references);
$isQuoted = \in_array($sequence[$i], ['"', "'"]);
$value = self::parseScalar($sequence, $flags, [',', ']'], $i, null === $tag, $references);

// the value can be an array if a reference has been resolved to an array var
if (\is_string($value) && !$isQuoted && false !== strpos($value, ': ')) {
@@ -403,9 +403,9 @@ private static function parseSequence(string $sequence, int $flags, int &$i = 0,
*
* @throws ParseException When malformed inline YAML string is parsed
*/
private static function parseMapping(string $mapping, int $flags, int &$i = 0, array $references = array())
private static function parseMapping(string $mapping, int $flags, int &$i = 0, array $references = [])
{
$output = array();
$output = [];
$len = \strlen($mapping);
++$i;
$allowOverwrite = false;
@@ -427,8 +427,8 @@ private static function parseMapping(string $mapping, int $flags, int &$i = 0, a

// key
$offsetBeforeKeyParsing = $i;
$isKeyQuoted = \in_array($mapping[$i], array('"', "'"), true);
$key = self::parseScalar($mapping, $flags, array(':', ' '), $i, false, array());
$isKeyQuoted = \in_array($mapping[$i], ['"', "'"], true);
$key = self::parseScalar($mapping, $flags, [':', ' '], $i, false, []);

if ($offsetBeforeKeyParsing === $i) {
throw new ParseException('Missing mapping key.', self::$parsedLineNumber + 1, $mapping);
@@ -446,7 +446,7 @@ private static function parseMapping(string $mapping, int $flags, int &$i = 0, a
}
}

if (!$isKeyQuoted && (!isset($mapping[$i + 1]) || !\in_array($mapping[$i + 1], array(' ', ',', '[', ']', '{', '}'), true))) {
if (!$isKeyQuoted && (!isset($mapping[$i + 1]) || !\in_array($mapping[$i + 1], [' ', ',', '[', ']', '{', '}'], true))) {
throw new ParseException('Colons must be followed by a space or an indication character (i.e. " ", ",", "[", "]", "{", "}").', self::$parsedLineNumber + 1, $mapping);
}

@@ -504,7 +504,7 @@ private static function parseMapping(string $mapping, int $flags, int &$i = 0, a
}
break;
default:
$value = self::parseScalar($mapping, $flags, array(',', '}'), $i, null === $tag, $references);
$value = self::parseScalar($mapping, $flags, [',', '}'], $i, null === $tag, $references);
// Spec: Keys MUST be unique; first one wins.
// Parser cannot abort this mapping earlier, since lines
// are processed sequentially.
@@ -538,7 +538,7 @@ private static function parseMapping(string $mapping, int $flags, int &$i = 0, a
*
* @throws ParseException when object parsing support was disabled and the parser detected a PHP object or when a reference could not be resolved
*/
private static function evaluateScalar(string $scalar, int $flags, array $references = array())
private static function evaluateScalar(string $scalar, int $flags, array $references = [])
{
$scalar = trim($scalar);
$scalarLower = strtolower($scalar);
@@ -670,7 +670,7 @@ private static function parseTag(string $value, int &$i, int $flags): ?string
$nextOffset += strspn($value, ' ', $nextOffset);

// Is followed by a scalar and is a built-in tag
if ($tag && (!isset($value[$nextOffset]) || !\in_array($value[$nextOffset], array('[', '{'), true)) && ('!' === $tag[0] || 'str' === $tag || 'php/const' === $tag || 'php/object' === $tag)) {
if ($tag && (!isset($value[$nextOffset]) || !\in_array($value[$nextOffset], ['[', '{'], true)) && ('!' === $tag[0] || 'str' === $tag || 'php/const' === $tag || 'php/object' === $tag)) {
// Manage in {@link self::evaluateScalar()}
return null;
}
34 changes: 17 additions & 17 deletions Parser.php
Original file line number Diff line number Diff line change
@@ -29,13 +29,13 @@ class Parser
private $filename;
private $offset = 0;
private $totalNumberOfLines;
private $lines = array();
private $lines = [];
private $currentLineNb = -1;
private $currentLine = '';
private $refs = array();
private $skippedLineNumbers = array();
private $locallySkippedLineNumbers = array();
private $refsBeingParsed = array();
private $refs = [];
private $skippedLineNumbers = [];
private $locallySkippedLineNumbers = [];
private $refsBeingParsed = [];

/**
* Parses a YAML file into a PHP value.
@@ -82,7 +82,7 @@ public function parse(string $value, int $flags = 0)
throw new ParseException('The YAML value does not appear to be valid UTF-8.', -1, null, $this->filename);
}

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

$mbEncoding = null;
$data = null;
@@ -98,11 +98,11 @@ public function parse(string $value, int $flags = 0)
if (null !== $mbEncoding) {
mb_internal_encoding($mbEncoding);
}
$this->lines = array();
$this->lines = [];
$this->currentLine = '';
$this->refs = array();
$this->skippedLineNumbers = array();
$this->locallySkippedLineNumbers = array();
$this->refs = [];
$this->skippedLineNumbers = [];
$this->locallySkippedLineNumbers = [];
}

return $data;
@@ -124,7 +124,7 @@ private function doParse(string $value, int $flags)
$this->currentLine = '';
$value = $this->cleanup($value);
$this->lines = explode("\n", $value);
$this->locallySkippedLineNumbers = array();
$this->locallySkippedLineNumbers = [];

if (null === $this->totalNumberOfLines) {
$this->totalNumberOfLines = \count($this->lines);
@@ -134,7 +134,7 @@ private function doParse(string $value, int $flags)
return null;
}

$data = array();
$data = [];
$context = null;
$allowOverwrite = false;

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

$data = array();
$data = [];
if ($this->getCurrentLineIndentation() >= $newIndent) {
$data[] = substr($this->currentLine, $newIndent);
} elseif ($this->isCurrentLineEmpty() || $this->isCurrentLineComment()) {
@@ -683,7 +683,7 @@ private function parseValue(string $value, int $flags, string $context)
return Inline::parse($value, $flags, $this->refs);
}

$lines = array();
$lines = [];

while ($this->moveToNextLine()) {
// unquoted strings end before the first unindented line
@@ -748,7 +748,7 @@ private function parseBlockScalar(string $style, string $chomping = '', int $ind
}

$isCurrentLineBlank = $this->isCurrentLineBlank();
$blockLines = array();
$blockLines = [];

// leading blank lines are consumed before determining indentation
while ($notEOF && $isCurrentLineBlank) {
@@ -920,7 +920,7 @@ private function isCurrentLineLastLineInDocument(): bool
*/
private function cleanup(string $value): string
{
$value = str_replace(array("\r\n", "\r"), "\n", $value);
$value = str_replace(["\r\n", "\r"], "\n", $value);

// strip YAML header
$count = 0;
14 changes: 7 additions & 7 deletions Tests/Command/LintCommandTest.php
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ public function testLintCorrectFile()
$tester = $this->createCommandTester();
$filename = $this->createFile('foo: bar');

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

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

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

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

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

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

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

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

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

protected function setUp()
{
$this->files = array();
$this->files = [];
@mkdir(sys_get_temp_dir().'/framework-yml-lint-test');
}

Loading