Skip to content

Commit

Permalink
[7.0] Remove remaining deprecated code paths
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Jul 5, 2023
1 parent a18ce1d commit e9c944f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 25 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

7.0
---

* Remove the `!php/const:` tag, use `!php/const` instead (without the colon)

6.3
---

Expand Down
11 changes: 3 additions & 8 deletions Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,9 @@ private function doParse(string $value, int $flags): mixed
array_pop($this->refsBeingParsed);
}
} elseif (
// @todo in 7.0 remove legacy "(?:!?!php/const:)?"
self::preg_match('#^(?P<key>(?:![^\s]++\s++)?(?:'.Inline::REGEX_QUOTED_STRING.'|(?:!?!php/const:)?[^ \'"\[\{!].*?)) *\:(( |\t)++(?P<value>.+))?$#u', rtrim($this->currentLine), $values)
self::preg_match('#^(?P<key>(?:![^\s]++\s++)?(?:'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\[\{!].*?)) *\:(( |\t)++(?P<value>.+))?$#u', rtrim($this->currentLine), $values)
&& (!str_contains($values['key'], ' #') || \in_array($values['key'][0], ['"', "'"]))
) {
if (str_starts_with($values['key'], '!php/const:')) {
trigger_deprecation('symfony/yaml', '6.2', 'YAML syntax for key "%s" is deprecated and replaced by "!php/const %s".', $values['key'], substr($values['key'], 11));
}

if ($context && 'sequence' == $context) {
throw new ParseException('You cannot define a mapping item when in a sequence.', $this->currentLineNb + 1, $this->currentLine, $this->filename);
}
Expand Down Expand Up @@ -413,7 +408,7 @@ private function doParse(string $value, int $flags): mixed
throw new ParseException('Multiple documents are not supported.', $this->currentLineNb + 1, $this->currentLine, $this->filename);
}

if ($deprecatedUsage = (isset($this->currentLine[1]) && '?' === $this->currentLine[0] && ' ' === $this->currentLine[1])) {
if (isset($this->currentLine[1]) && '?' === $this->currentLine[0] && ' ' === $this->currentLine[1]) {
throw new ParseException('Complex mappings are not supported.', $this->getRealCurrentLineNb() + 1, $this->currentLine);
}

Expand Down Expand Up @@ -443,7 +438,7 @@ private function doParse(string $value, int $flags): mixed
continue;
}
// If the indentation is not consistent at offset 0, it is to be considered as a ParseError
if (0 === $this->offset && !$deprecatedUsage && isset($line[0]) && ' ' === $line[0]) {
if (0 === $this->offset && isset($line[0]) && ' ' === $line[0]) {
throw new ParseException('Unable to parse.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/InlineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ public function testTheEmptyStringIsAValidMappingKey()
/**
* @dataProvider getNotPhpCompatibleMappingKeyData
*/
public function testImplicitStringCastingOfMappingKeysIsDeprecated($yaml, $expected)
public function testImplicitStringCastingOfMappingKeysThrows($yaml, $expected)
{
$this->expectException(ParseException::class);
$this->expectExceptionMessage('Implicit casting of incompatible mapping keys to strings is not supported. Quote your evaluable mapping keys instead');
Expand Down
18 changes: 2 additions & 16 deletions Tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@
namespace Symfony\Component\Yaml\Tests;

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Parser;
use Symfony\Component\Yaml\Tag\TaggedValue;
use Symfony\Component\Yaml\Yaml;

class ParserTest extends TestCase
{
use ExpectDeprecationTrait;

private ?Parser $parser;

protected function setUp(): void
Expand Down Expand Up @@ -662,7 +659,7 @@ public function testObjectsSupportDisabledWithExceptions()
$this->parser->parse($yaml, Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE);
}

public function testMappingKeyInMultiLineStringTriggersDeprecationNotice()
public function testMappingKeyInMultiLineStringThrowsException()
{
$this->expectException(ParseException::class);
$this->expectExceptionMessage('Mapping values are not allowed in multi-line blocks at line 2 (near "dbal:wrong").');
Expand Down Expand Up @@ -2483,25 +2480,14 @@ public function testPhpConstantTagMappingKey()
$this->assertSame($expected, $this->parser->parse($yaml, Yaml::PARSE_CONSTANT));
}

public function testDeprecatedPhpConstantSyntax()
public function testWrongPhpConstantSyntax()
{
$this->expectException(ParseException::class);
$this->expectExceptionMessage('Missing value for tag "php/const:App\Kernel::SEMART_VERSION" at line 1 (near "!php/const:App\Kernel::SEMART_VERSION").');

$this->parser->parse('!php/const:App\Kernel::SEMART_VERSION', Yaml::PARSE_CUSTOM_TAGS | Yaml::PARSE_CONSTANT);
}

/**
* @group legacy
*/
public function testDeprecatedPhpConstantSyntaxAsScalarKey()
{
$this->expectDeprecation('Since symfony/yaml 6.2: YAML syntax for key "!php/const:Symfony\Component\Yaml\Tests\B::BAR" is deprecated and replaced by "!php/const Symfony\Component\Yaml\Tests\B::BAR".');
$actual = $this->parser->parse('!php/const:Symfony\Component\Yaml\Tests\B::BAR: value', Yaml::PARSE_CUSTOM_TAGS | Yaml::PARSE_CONSTANT);

$this->assertSame(['bar' => 'value'], $actual);
}

public function testPhpConstantTagMappingAsScalarKey()
{
$yaml = <<<YAML
Expand Down

0 comments on commit e9c944f

Please sign in to comment.