public function __construct()
{
- if (func_num_args() > 0) {
+ if (\func_num_args() > 0) {
@trigger_error(sprintf('The constructor arguments $offset, $totalNumberOfLines, $skippedLineNumbers of %s are deprecated and will be removed in 4.0', self::class), E_USER_DEPRECATED);
$this->offset = func_get_arg(0);
- if (func_num_args() > 1) {
+ if (\func_num_args() > 1) {
$this->totalNumberOfLines = func_get_arg(1);
}
- if (func_num_args() > 2) {
+ if (\func_num_args() > 2) {
$this->skippedLineNumbers = func_get_arg(2);
}
}
*/
public function parse($value, $flags = 0)
{
- if (is_bool($flags)) {
+ if (\is_bool($flags)) {
@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);
if ($flags) {
}
}
- if (func_num_args() >= 3) {
+ if (\func_num_args() >= 3) {
@trigger_error('Passing a boolean flag to toggle object support is deprecated since Symfony 3.1 and will be removed in 4.0. Use the Yaml::PARSE_OBJECT flag instead.', E_USER_DEPRECATED);
if (func_get_arg(2)) {
}
}
- if (func_num_args() >= 4) {
+ if (\func_num_args() >= 4) {
@trigger_error('Passing a boolean flag to toggle object for map support is deprecated since Symfony 3.1 and will be removed in 4.0. Use the Yaml::PARSE_OBJECT_FOR_MAP flag instead.', E_USER_DEPRECATED);
if (func_get_arg(3)) {
$this->locallySkippedLineNumbers = array();
if (null === $this->totalNumberOfLines) {
- $this->totalNumberOfLines = count($this->lines);
+ $this->totalNumberOfLines = \count($this->lines);
}
if (!$this->moveToNextLine()) {
// this is a compact notation element, add to next block and parse
$block = $values['value'];
if ($this->isNextLineIndented()) {
- $block .= "\n".$this->getNextEmbedBlock($this->getCurrentLineIndentation() + strlen($values['leadspaces']) + 1);
+ $block .= "\n".$this->getNextEmbedBlock($this->getCurrentLineIndentation() + \strlen($values['leadspaces']) + 1);
}
$data[] = $this->parseBlock($this->getRealCurrentLineNb(), $block, $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], array('"', "'")))
) {
if ($context && 'sequence' == $context) {
throw new ParseException('You cannot define a mapping item when in a sequence', $this->currentLineNb + 1, $this->currentLine, $this->filename);
throw $e;
}
- if (!is_string($key) && !is_int($key)) {
+ if (!\is_string($key) && !\is_int($key)) {
$keyType = is_numeric($key) ? 'numeric key' : 'non-string key';
@trigger_error($this->getDeprecationMessage(sprintf('Implicit casting of %s to string is deprecated since Symfony 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead.', $keyType)), E_USER_DEPRECATED);
}
// Convert float keys to strings, to avoid being converted to integers by PHP
- if (is_float($key)) {
+ if (\is_float($key)) {
$key = (string) $key;
}
$refValue = (array) $refValue;
}
- if (!is_array($refValue)) {
+ if (!\is_array($refValue)) {
throw new ParseException('YAML merge keys used with a scalar value instead of an array.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
}
$parsed = (array) $parsed;
}
- if (!is_array($parsed)) {
+ if (!\is_array($parsed)) {
throw new ParseException('YAML merge keys used with a scalar value instead of an array.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
}
$parsedItem = (array) $parsedItem;
}
- if (!is_array($parsedItem)) {
+ if (!\is_array($parsedItem)) {
throw new ParseException('Merge items must be arrays.', $this->getRealCurrentLineNb() + 1, $parsedItem, $this->filename);
}
}
// 1-liner optionally followed by newline(s)
- if (is_string($value) && $this->lines[0] === trim($value)) {
+ if (\is_string($value) && $this->lines[0] === trim($value)) {
try {
$value = Inline::parse($this->lines[0], $flags, $this->refs);
} catch (ParseException $e) {
$data = new TaggedValue($tag, $data);
}
- if (Yaml::PARSE_OBJECT_FOR_MAP & $flags && !is_object($data) && 'mapping' === $context) {
+ if (Yaml::PARSE_OBJECT_FOR_MAP & $flags && !\is_object($data) && 'mapping' === $context) {
$object = new \stdClass();
foreach ($data as $key => $value) {
*/
private function getCurrentLineIndentation()
{
- return strlen($this->currentLine) - strlen(ltrim($this->currentLine, ' '));
+ return \strlen($this->currentLine) - \strlen(ltrim($this->currentLine, ' '));
}
/**
private function getNextEmbedBlock($indentation = null, $inSequence = false)
{
$oldLineIndentation = $this->getCurrentLineIndentation();
- $blockScalarIndentations = array();
-
- if ($this->isBlockScalarHeader()) {
- $blockScalarIndentations[] = $oldLineIndentation;
- }
if (!$this->moveToNextLine()) {
return;
$isItUnindentedCollection = $this->isStringUnIndentedCollectionItem();
- if (empty($blockScalarIndentations) && $this->isBlockScalarHeader()) {
- $blockScalarIndentations[] = $this->getCurrentLineIndentation();
- }
-
- $previousLineIndentation = $this->getCurrentLineIndentation();
-
while ($this->moveToNextLine()) {
$indent = $this->getCurrentLineIndentation();
- // terminate all block scalars that are more indented than the current line
- if (!empty($blockScalarIndentations) && $indent < $previousLineIndentation && '' !== trim($this->currentLine)) {
- foreach ($blockScalarIndentations as $key => $blockScalarIndentation) {
- if ($blockScalarIndentation >= $indent) {
- unset($blockScalarIndentations[$key]);
- }
- }
- }
-
- if (empty($blockScalarIndentations) && !$this->isCurrentLineComment() && $this->isBlockScalarHeader()) {
- $blockScalarIndentations[] = $indent;
- }
-
- $previousLineIndentation = $indent;
-
if ($isItUnindentedCollection && !$this->isCurrentLineEmpty() && !$this->isStringUnIndentedCollectionItem() && $newIndent === $indent) {
$this->moveToPreviousLine();
break;
*/
private function moveToNextLine()
{
- if ($this->currentLineNb >= count($this->lines) - 1) {
+ if ($this->currentLineNb >= \count($this->lines) - 1) {
return false;
}
}
}
- for ($i = 0, $linesCount = count($lines), $previousLineBlank = false; $i < $linesCount; ++$i) {
+ for ($i = 0, $linesCount = \count($lines), $previousLineBlank = false; $i < $linesCount; ++$i) {
if ('' === $lines[$i]) {
$value .= "\n";
$previousLineBlank = true;
$parsedValue = Inline::parse($value, $flags, $this->refs);
- if ('mapping' === $context && is_string($parsedValue) && '"' !== $value[0] && "'" !== $value[0] && '[' !== $value[0] && '{' !== $value[0] && '!' !== $value[0] && false !== strpos($parsedValue, ': ')) {
+ if ('mapping' === $context && \is_string($parsedValue) && '"' !== $value[0] && "'" !== $value[0] && '[' !== $value[0] && '{' !== $value[0] && '!' !== $value[0] && false !== strpos($parsedValue, ': ')) {
throw new ParseException('A colon cannot be used in an unquoted mapping value.', $this->getRealCurrentLineNb() + 1, $value, $this->filename);
}
// determine indentation if not specified
if (0 === $indentation) {
if (self::preg_match('/^ +/', $this->currentLine, $matches)) {
- $indentation = strlen($matches[0]);
+ $indentation = \strlen($matches[0]);
}
}
self::preg_match($pattern, $this->currentLine, $matches)
)
) {
- if ($isCurrentLineBlank && strlen($this->currentLine) > $indentation) {
+ if ($isCurrentLineBlank && \strlen($this->currentLine) > $indentation) {
$blockLines[] = substr($this->currentLine, $indentation);
} elseif ($isCurrentLineBlank) {
$blockLines[] = '';
$previousLineIndented = false;
$previousLineBlank = false;
- for ($i = 0, $blockLinesCount = count($blockLines); $i < $blockLinesCount; ++$i) {
+ for ($i = 0, $blockLinesCount = \count($blockLines); $i < $blockLinesCount; ++$i) {
if ('' === $blockLines[$i]) {
$text .= "\n";
$previousLineIndented = false;
return '-' === rtrim($this->currentLine) || 0 === strpos($this->currentLine, '- ');
}
- /**
- * Tests whether or not the current line is the header of a block scalar.
- *
- * @return bool
- */
- private function isBlockScalarHeader()
- {
- return (bool) self::preg_match('~'.self::BLOCK_SCALAR_HEADER_PATTERN.'$~', $this->currentLine);
- }
-
/**
* A local wrapper for `preg_match` which will throw a ParseException if there
* is an internal error in the PCRE engine.