Skip to content

Commit e9c944f

Browse files
[7.0] Remove remaining deprecated code paths
1 parent a18ce1d commit e9c944f

File tree

4 files changed

+11
-25
lines changed

4 files changed

+11
-25
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.0
5+
---
6+
7+
* Remove the `!php/const:` tag, use `!php/const` instead (without the colon)
8+
49
6.3
510
---
611

Parser.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,9 @@ private function doParse(string $value, int $flags): mixed
198198
array_pop($this->refsBeingParsed);
199199
}
200200
} elseif (
201-
// @todo in 7.0 remove legacy "(?:!?!php/const:)?"
202-
self::preg_match('#^(?P<key>(?:![^\s]++\s++)?(?:'.Inline::REGEX_QUOTED_STRING.'|(?:!?!php/const:)?[^ \'"\[\{!].*?)) *\:(( |\t)++(?P<value>.+))?$#u', rtrim($this->currentLine), $values)
201+
self::preg_match('#^(?P<key>(?:![^\s]++\s++)?(?:'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\[\{!].*?)) *\:(( |\t)++(?P<value>.+))?$#u', rtrim($this->currentLine), $values)
203202
&& (!str_contains($values['key'], ' #') || \in_array($values['key'][0], ['"', "'"]))
204203
) {
205-
if (str_starts_with($values['key'], '!php/const:')) {
206-
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));
207-
}
208-
209204
if ($context && 'sequence' == $context) {
210205
throw new ParseException('You cannot define a mapping item when in a sequence.', $this->currentLineNb + 1, $this->currentLine, $this->filename);
211206
}
@@ -413,7 +408,7 @@ private function doParse(string $value, int $flags): mixed
413408
throw new ParseException('Multiple documents are not supported.', $this->currentLineNb + 1, $this->currentLine, $this->filename);
414409
}
415410

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

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

Tests/InlineTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ public function testTheEmptyStringIsAValidMappingKey()
824824
/**
825825
* @dataProvider getNotPhpCompatibleMappingKeyData
826826
*/
827-
public function testImplicitStringCastingOfMappingKeysIsDeprecated($yaml, $expected)
827+
public function testImplicitStringCastingOfMappingKeysThrows($yaml, $expected)
828828
{
829829
$this->expectException(ParseException::class);
830830
$this->expectExceptionMessage('Implicit casting of incompatible mapping keys to strings is not supported. Quote your evaluable mapping keys instead');

Tests/ParserTest.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,13 @@
1212
namespace Symfony\Component\Yaml\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1615
use Symfony\Component\Yaml\Exception\ParseException;
1716
use Symfony\Component\Yaml\Parser;
1817
use Symfony\Component\Yaml\Tag\TaggedValue;
1918
use Symfony\Component\Yaml\Yaml;
2019

2120
class ParserTest extends TestCase
2221
{
23-
use ExpectDeprecationTrait;
24-
2522
private ?Parser $parser;
2623

2724
protected function setUp(): void
@@ -662,7 +659,7 @@ public function testObjectsSupportDisabledWithExceptions()
662659
$this->parser->parse($yaml, Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE);
663660
}
664661

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

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

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

2494-
/**
2495-
* @group legacy
2496-
*/
2497-
public function testDeprecatedPhpConstantSyntaxAsScalarKey()
2498-
{
2499-
$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".');
2500-
$actual = $this->parser->parse('!php/const:Symfony\Component\Yaml\Tests\B::BAR: value', Yaml::PARSE_CUSTOM_TAGS | Yaml::PARSE_CONSTANT);
2501-
2502-
$this->assertSame(['bar' => 'value'], $actual);
2503-
}
2504-
25052491
public function testPhpConstantTagMappingAsScalarKey()
25062492
{
25072493
$yaml = <<<YAML

0 commit comments

Comments
 (0)