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.0.13
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.0.14
Choose a head ref
  • 11 commits
  • 10 files changed
  • 3 contributors

Commits on Jul 22, 2018

  1. Use an empty string as default for assertEquals

    Make sure it isn’t interpreted as a type NULL, making the test fail with
    PHPUnit 7.2.
    DavidPrevot committed Jul 22, 2018
    Copy the full SHA
    4598d79 View commit details

Commits on Jul 24, 2018

  1. Copy the full SHA
    acaaa95 View commit details

Commits on Jul 26, 2018

  1. Merge branch '2.8' into 3.4

    * 2.8:
      Fix Clidumper tests
      Enable the fixer enforcing fully-qualified calls for compiler-optimized functions
      Apply fixers
      Disable the native_constant_invocation fixer until it can be scoped
      Update the list of excluded files for the CS fixer
    nicolas-grekas committed Jul 26, 2018
    Copy the full SHA
    2ed2a51 View commit details
  2. Merge branch '3.4' into 4.0

    * 3.4:
      Fix Clidumper tests
      Enable the fixer enforcing fully-qualified calls for compiler-optimized functions
      Apply fixers
      Disable the native_constant_invocation fixer until it can be scoped
      Update the list of excluded files for the CS fixer
    nicolas-grekas committed Jul 26, 2018
    Copy the full SHA
    c4d091d View commit details
  3. Copy the full SHA
    fbf8766 View commit details
  4. Merge branch '2.8' into 3.4

    * 2.8:
      Alpha-ordering for "use" statements
    nicolas-grekas committed Jul 26, 2018
    Copy the full SHA
    87bd4af View commit details
  5. Merge branch '3.4' into 4.0

    * 3.4:
      Alpha-ordering for "use" statements
    nicolas-grekas committed Jul 26, 2018
    Copy the full SHA
    2e50b32 View commit details
  6. minor #28025 Use an empty string as default for assertEquals (DavidPr…

    …evot)
    
    This PR was merged into the 3.4 branch.
    
    Discussion
    ----------
    
    Use an empty string as default for assertEquals
    
    Make sure it isn’t interpreted as a type NULL, making the test fail with PHPUnit 7.2.
    
    | Q             | A
    | ------------- | ---
    | Branch?       | 3.4
    | Bug fix?      | no
    | New feature?  | no
    | BC breaks?    | no
    | Deprecations? | no
    | Tests pass?   | yes
    | License       | MIT
    
    This shouldn’t break the existing tests, but will also make them work with recent PHPUnit.
    
    Commits
    -------
    
    31353147a3 Use an empty string as default for assertEquals
    nicolas-grekas committed Jul 26, 2018
    Copy the full SHA
    dfc2bcb View commit details
  7. Merge branch '3.4' into 4.0

    * 3.4:
      Fix tests for legacy phpunit versions
      Add missing Ukrainian translations
      Use an empty string as default for assertEquals
    nicolas-grekas committed Jul 26, 2018
    Copy the full SHA
    7411d22 View commit details
  8. Merge branch '2.8' into 3.4

    * 2.8:
      Enable native_constant_invocation CS fixer
    nicolas-grekas committed Jul 26, 2018
    Copy the full SHA
    810af2d View commit details
  9. Merge branch '3.4' into 4.0

    * 3.4:
      Enable native_constant_invocation CS fixer
    nicolas-grekas committed Jul 26, 2018
    Copy the full SHA
    05f66d7 View commit details
Showing with 59 additions and 59 deletions.
  1. +4 −4 Command/LintCommand.php
  2. +3 −3 Dumper.php
  3. +1 −1 Escaper.php
  4. +25 −25 Inline.php
  5. +17 −17 Parser.php
  6. +1 −1 Tests/Command/LintCommandTest.php
  7. +1 −1 Tests/DumperTest.php
  8. +1 −1 Tests/Fixtures/escapedCharacters.yml
  9. +2 −2 Tests/ParserTest.php
  10. +4 −4 Unescaper.php
8 changes: 4 additions & 4 deletions Command/LintCommand.php
Original file line number Diff line number Diff line change
@@ -141,7 +141,7 @@ private function display(SymfonyStyle $io, array $files)

private function displayTxt(SymfonyStyle $io, array $filesInfo)
{
$countFiles = count($filesInfo);
$countFiles = \count($filesInfo);
$erroredFiles = 0;

foreach ($filesInfo as $info) {
@@ -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(), array('yml', 'yaml'))) {
continue;
}

@@ -229,7 +229,7 @@ private function getDirectoryIterator($directory)
};

if (null !== $this->directoryIteratorProvider) {
return call_user_func($this->directoryIteratorProvider, $directory, $default);
return \call_user_func($this->directoryIteratorProvider, $directory, $default);
}

return $default($directory);
@@ -242,7 +242,7 @@ private function isReadable($fileOrDirectory)
};

if (null !== $this->isReadableProvider) {
return call_user_func($this->isReadableProvider, $fileOrDirectory, $default);
return \call_user_func($this->isReadableProvider, $fileOrDirectory, $default);
}

return $default($fileOrDirectory);
6 changes: 3 additions & 3 deletions Dumper.php
Original file line number Diff line number Diff line change
@@ -56,13 +56,13 @@ public function dump($input, int $inline = 0, int $indent = 0, int $flags = 0):
$dumpObjectAsInlineMap = empty((array) $input);
}

if ($inline <= 0 || (!is_array($input) && $dumpObjectAsInlineMap) || empty($input)) {
if ($inline <= 0 || (!\is_array($input) && $dumpObjectAsInlineMap) || empty($input)) {
$output .= $prefix.Inline::dump($input, $flags);
} else {
$dumpAsMap = Inline::isHash($input);

foreach ($input as $key => $value) {
if ($inline >= 1 && Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && is_string($value) && false !== strpos($value, "\n") && false === strpos($value, "\r\n")) {
if ($inline >= 1 && Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $flags && \is_string($value) && false !== strpos($value, "\n") && false === strpos($value, "\r\n")) {
// If the first line starts with a space character, the spec requires a blockIndicationIndicator
// http://www.yaml.org/spec/1.2/spec.html#id2793979
$blockIndentationIndicator = (' ' === substr($value, 0, 1)) ? (string) $this->indentation : '';
@@ -81,7 +81,7 @@ public function dump($input, int $inline = 0, int $indent = 0, int $flags = 0):
$dumpObjectAsInlineMap = empty((array) $value);
}

$willBeInlined = $inline - 1 <= 0 || !is_array($value) && $dumpObjectAsInlineMap || empty($value);
$willBeInlined = $inline - 1 <= 0 || !\is_array($value) && $dumpObjectAsInlineMap || empty($value);

$output .= sprintf('%s%s%s%s',
$prefix,
2 changes: 1 addition & 1 deletion Escaper.php
Original file line number Diff line number Diff line change
@@ -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), array('null', '~', 'true', 'false', 'y', 'n', 'yes', 'no', 'on', 'off'))) {
return true;
}

50 changes: 25 additions & 25 deletions Inline.php
Original file line number Diff line number Diff line change
@@ -11,8 +11,8 @@

namespace Symfony\Component\Yaml;

use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Exception\DumpException;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Tag\TaggedValue;

/**
@@ -122,15 +122,15 @@ public static function parse(string $value = null, int $flags = 0, array $refere
public static function dump($value, int $flags = 0): string
{
switch (true) {
case is_resource($value):
case \is_resource($value):
if (Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE & $flags) {
throw new DumpException(sprintf('Unable to dump PHP resources in a YAML file ("%s").', get_resource_type($value)));
}

return 'null';
case $value instanceof \DateTimeInterface:
return $value->format('c');
case is_object($value):
case \is_object($value):
if ($value instanceof TaggedValue) {
return '!'.$value->getTag().' '.self::dump($value->getValue(), $flags);
}
@@ -154,7 +154,7 @@ public static function dump($value, int $flags = 0): string
}

return 'null';
case is_array($value):
case \is_array($value):
return self::dumpArray($value, $flags);
case null === $value:
return 'null';
@@ -163,13 +163,13 @@ public static function dump($value, int $flags = 0): string
case false === $value:
return 'false';
case ctype_digit($value):
return is_string($value) ? "'$value'" : (int) $value;
return \is_string($value) ? "'$value'" : (int) $value;
case is_numeric($value):
$locale = setlocale(LC_NUMERIC, 0);
if (false !== $locale) {
setlocale(LC_NUMERIC, 'C');
}
if (is_float($value)) {
if (\is_float($value)) {
$repr = (string) $value;
if (is_infinite($value)) {
$repr = str_ireplace('INF', '.Inf', $repr);
@@ -178,7 +178,7 @@ public static function dump($value, int $flags = 0): string
$repr = '!!float '.$repr;
}
} else {
$repr = is_string($value) ? "'$value'" : (string) $value;
$repr = \is_string($value) ? "'$value'" : (string) $value;
}
if (false !== $locale) {
setlocale(LC_NUMERIC, $locale);
@@ -263,7 +263,7 @@ private static function dumpArray(array $value, int $flags): string
*/
public static function parseScalar(string $scalar, int $flags = 0, array $delimiters = null, int &$i = 0, bool $evaluate = true, array $references = array())
{
if (in_array($scalar[$i], array('"', "'"))) {
if (\in_array($scalar[$i], array('"', "'"))) {
// quoted scalar
$output = self::parseQuotedScalar($scalar, $i);

@@ -272,23 +272,23 @@ public static function parseScalar(string $scalar, int $flags = 0, array $delimi
if ('' === $tmp) {
throw new ParseException(sprintf('Unexpected end of line, expected one of "%s".', implode($delimiters)), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
}
if (!in_array($tmp[0], $delimiters)) {
if (!\in_array($tmp[0], $delimiters)) {
throw new ParseException(sprintf('Unexpected characters (%s).', substr($scalar, $i)), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
}
}
} else {
// "normal" string
if (!$delimiters) {
$output = substr($scalar, $i);
$i += strlen($output);
$i += \strlen($output);

// remove comments
if (Parser::preg_match('/[ \t]+#/', $output, $match, PREG_OFFSET_CAPTURE)) {
$output = substr($output, 0, $match[0][1]);
}
} elseif (Parser::preg_match('/^(.*?)('.implode('|', $delimiters).')/', substr($scalar, $i), $match)) {
$output = $match[1];
$i += strlen($output);
$i += \strlen($output);
$output = trim($output);
} else {
throw new ParseException(sprintf('Malformed inline YAML string: %s.', $scalar), self::$parsedLineNumber + 1, null, self::$parsedFilename);
@@ -318,7 +318,7 @@ private static function parseQuotedScalar(string $scalar, int &$i): string
throw new ParseException(sprintf('Malformed inline YAML string: %s.', substr($scalar, $i)), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
}

$output = substr($match[0], 1, strlen($match[0]) - 2);
$output = substr($match[0], 1, \strlen($match[0]) - 2);

$unescaper = new Unescaper();
if ('"' == $scalar[$i]) {
@@ -327,7 +327,7 @@ private static function parseQuotedScalar(string $scalar, int &$i): string
$output = $unescaper->unescapeSingleQuotedString($output);
}

$i += strlen($match[0]);
$i += \strlen($match[0]);

return $output;
}
@@ -340,7 +340,7 @@ private static function parseQuotedScalar(string $scalar, int &$i): string
private static function parseSequence(string $sequence, int $flags, int &$i = 0, array $references = array()): array
{
$output = array();
$len = strlen($sequence);
$len = \strlen($sequence);
++$i;

// [foo, bar, ...]
@@ -365,11 +365,11 @@ 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('"', "'"));
$isQuoted = \in_array($sequence[$i], array('"', "'"));
$value = self::parseScalar($sequence, $flags, array(',', ']'), $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, ': ')) {
if (\is_string($value) && !$isQuoted && false !== strpos($value, ': ')) {
// embedded mapping?
try {
$pos = 0;
@@ -404,7 +404,7 @@ private static function parseSequence(string $sequence, int $flags, int &$i = 0,
private static function parseMapping(string $mapping, int $flags, int &$i = 0, array $references = array())
{
$output = array();
$len = strlen($mapping);
$len = \strlen($mapping);
++$i;
$allowOverwrite = false;

@@ -425,7 +425,7 @@ private static function parseMapping(string $mapping, int $flags, int &$i = 0, a

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

if ($offsetBeforeKeyParsing === $i) {
@@ -439,12 +439,12 @@ private static function parseMapping(string $mapping, int $flags, int &$i = 0, a
if (!$isKeyQuoted) {
$evaluatedKey = self::evaluateScalar($key, $flags, $references);

if ('' !== $key && $evaluatedKey !== $key && !is_string($evaluatedKey) && !is_int($evaluatedKey)) {
if ('' !== $key && $evaluatedKey !== $key && !\is_string($evaluatedKey) && !\is_int($evaluatedKey)) {
throw new ParseException('Implicit casting of incompatible mapping keys to strings is not supported. Quote your evaluable mapping keys instead.', self::$parsedLineNumber + 1, $mapping);
}
}

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

@@ -588,8 +588,8 @@ private static function evaluateScalar(string $scalar, int $flags, array $refere
case 0 === strpos($scalar, '!php/const'):
if (self::$constantSupport) {
$i = 0;
if (defined($const = self::parseScalar(substr($scalar, 11), 0, null, $i, false))) {
return constant($const);
if (\defined($const = self::parseScalar(substr($scalar, 11), 0, null, $i, false))) {
return \constant($const);
}

throw new ParseException(sprintf('The constant "%s" is not defined.', $const), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
@@ -668,7 +668,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], array('[', '{'), true)) && ('!' === $tag[0] || 'str' === $tag || 'php/const' === $tag || 'php/object' === $tag)) {
// Manage in {@link self::evaluateScalar()}
return null;
}
@@ -691,8 +691,8 @@ public static function evaluateBinaryScalar(string $scalar): string
{
$parsedBinaryData = self::parseScalar(preg_replace('/\s/', '', $scalar));

if (0 !== (strlen($parsedBinaryData) % 4)) {
throw new ParseException(sprintf('The normalized base64 encoded data (data without whitespace characters) length must be a multiple of four (%d bytes given).', strlen($parsedBinaryData)), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
if (0 !== (\strlen($parsedBinaryData) % 4)) {
throw new ParseException(sprintf('The normalized base64 encoded data (data without whitespace characters) length must be a multiple of four (%d bytes given).', \strlen($parsedBinaryData)), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
}

if (!Parser::preg_match('#^[A-Z0-9+/]+={0,2}$#i', $parsedBinaryData)) {
Loading