Skip to content

Commit aae9724

Browse files
feature #41360 [Yaml] Remove deprecated code (fancyweb)
This PR was merged into the 6.0 branch. Discussion ---------- [Yaml] Remove deprecated code | Q | A | ------------- | --- | Branch? | 6.0 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Commits ------- e8452cb [Yaml] Remove deprecated code
2 parents bb33ce0 + e8452cb commit aae9724

File tree

2 files changed

+31
-69
lines changed

2 files changed

+31
-69
lines changed

src/Symfony/Component/Yaml/Inline.php

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -601,9 +601,7 @@ private static function evaluateScalar(string $scalar, int $flags, array &$refer
601601
case 0 === strncmp($scalar, '!php/object', 11):
602602
if (self::$objectSupport) {
603603
if (!isset($scalar[12])) {
604-
trigger_deprecation('symfony/yaml', '5.1', 'Using the !php/object tag without a value is deprecated.');
605-
606-
return false;
604+
throw new ParseException('Missing value for tag "!php/object".', self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
607605
}
608606

609607
return unserialize(self::parseScalar(substr($scalar, 12)));
@@ -617,9 +615,7 @@ private static function evaluateScalar(string $scalar, int $flags, array &$refer
617615
case 0 === strncmp($scalar, '!php/const', 10):
618616
if (self::$constantSupport) {
619617
if (!isset($scalar[11])) {
620-
trigger_deprecation('symfony/yaml', '5.1', 'Using the !php/const tag without a value is deprecated.');
621-
622-
return '';
618+
throw new ParseException('Missing value for tag "!php/const".', self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
623619
}
624620

625621
$i = 0;
@@ -660,22 +656,7 @@ private static function evaluateScalar(string $scalar, int $flags, array &$refer
660656

661657
switch (true) {
662658
case ctype_digit($scalar):
663-
if (preg_match('/^0[0-7]+$/', $scalar)) {
664-
trigger_deprecation('symfony/yaml', '5.1', 'Support for parsing numbers prefixed with 0 as octal numbers. They will be parsed as strings as of 6.0.');
665-
666-
return octdec($scalar);
667-
}
668-
669-
$cast = (int) $scalar;
670-
671-
return ($scalar === (string) $cast) ? $cast : $scalar;
672659
case '-' === $scalar[0] && ctype_digit(substr($scalar, 1)):
673-
if (preg_match('/^-0[0-7]+$/', $scalar)) {
674-
trigger_deprecation('symfony/yaml', '5.1', 'Support for parsing numbers prefixed with 0 as octal numbers. They will be parsed as strings as of 6.0.');
675-
676-
return -octdec(substr($scalar, 1));
677-
}
678-
679660
$cast = (int) $scalar;
680661

681662
return ($scalar === (string) $cast) ? $cast : $scalar;

src/Symfony/Component/Yaml/Tests/InlineTest.php

Lines changed: 29 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -757,92 +757,73 @@ public function getTestsForOctalNumbers()
757757
}
758758

759759
/**
760-
* @group legacy
761760
* @dataProvider getTestsForOctalNumbersYaml11Notation
762761
*/
763-
public function testParseOctalNumbersYaml11Notation(int $expected, string $yaml)
762+
public function testParseOctalNumbersYaml11Notation(string $expected, string $yaml)
764763
{
765-
$this->expectDeprecation('Since symfony/yaml 5.1: Support for parsing numbers prefixed with 0 as octal numbers. They will be parsed as strings as of 6.0.');
766-
767764
self::assertSame($expected, Inline::parse($yaml));
768765
}
769766

770767
public function getTestsForOctalNumbersYaml11Notation()
771768
{
772769
return [
773-
'positive octal number' => [28, '034'],
774-
'positive octal number with separator' => [1243, '0_2_3_3_3'],
775-
'negative octal number' => [-28, '-034'],
770+
'positive octal number' => ['034', '034'],
771+
'positive octal number with separator' => ['02333', '0_2_3_3_3'],
772+
'negative octal number' => ['-034', '-034'],
773+
'invalid positive octal number' => ['0123456789', '0123456789'],
774+
'invalid negative octal number' => ['-0123456789', '-0123456789'],
776775
];
777776
}
778777

779778
/**
780779
* @dataProvider phpObjectTagWithEmptyValueProvider
781-
*
782-
* @group legacy
783780
*/
784-
public function testPhpObjectWithEmptyValue($expected, $value)
781+
public function testPhpObjectWithEmptyValue(string $value)
785782
{
786-
$this->expectDeprecation('Since symfony/yaml 5.1: Using the !php/object tag without a value is deprecated.');
783+
$this->expectException(ParseException::class);
784+
$this->expectExceptionMessage('Missing value for tag "!php/object" at line 1 (near "!php/object").');
787785

788-
$this->assertSame($expected, Inline::parse($value, Yaml::PARSE_OBJECT));
786+
Inline::parse($value, Yaml::PARSE_OBJECT);
789787
}
790788

791789
public function phpObjectTagWithEmptyValueProvider()
792790
{
793791
return [
794-
[false, '!php/object'],
795-
[false, '!php/object '],
796-
[false, '!php/object '],
797-
[[false], '[!php/object]'],
798-
[[false], '[!php/object ]'],
799-
[[false, 'foo'], '[!php/object , foo]'],
792+
['!php/object'],
793+
['!php/object '],
794+
['!php/object '],
795+
['[!php/object]'],
796+
['[!php/object ]'],
797+
['[!php/object , foo]'],
800798
];
801799
}
802800

803801
/**
804802
* @dataProvider phpConstTagWithEmptyValueProvider
805-
*
806-
* @group legacy
807803
*/
808-
public function testPhpConstTagWithEmptyValue($expected, $value)
804+
public function testPhpConstTagWithEmptyValue(string $value)
809805
{
810-
$this->expectDeprecation('Since symfony/yaml 5.1: Using the !php/const tag without a value is deprecated.');
806+
$this->expectException(ParseException::class);
807+
$this->expectExceptionMessage('Missing value for tag "!php/const" at line 1 (near "!php/const").');
811808

812-
$this->assertSame($expected, Inline::parse($value, Yaml::PARSE_CONSTANT));
809+
Inline::parse($value, Yaml::PARSE_CONSTANT);
813810
}
814811

815812
public function phpConstTagWithEmptyValueProvider()
816813
{
817814
return [
818-
['', '!php/const'],
819-
['', '!php/const '],
820-
['', '!php/const '],
821-
[[''], '[!php/const]'],
822-
[[''], '[!php/const ]'],
823-
[['', 'foo'], '[!php/const , foo]'],
824-
[['' => 'foo'], '{!php/const: foo}'],
825-
[['' => 'foo'], '{!php/const : foo}'],
826-
[['' => 'foo', 'bar' => 'ccc'], '{!php/const : foo, bar: ccc}'],
815+
['!php/const'],
816+
['!php/const '],
817+
['!php/const '],
818+
['[!php/const]'],
819+
['[!php/const ]'],
820+
['[!php/const , foo]'],
821+
['{!php/const: foo}'],
822+
['{!php/const : foo}'],
823+
['{!php/const : foo, bar: ccc}'],
827824
];
828825
}
829826

830-
/**
831-
* @group legacy
832-
*/
833-
public function testParsePositiveOctalNumberContainingInvalidDigits()
834-
{
835-
self::assertSame('0123456789', Inline::parse('0123456789'));
836-
}
837-
838-
/**
839-
* @group legacy
840-
*/
841-
public function testParseNegativeOctalNumberContainingInvalidDigits()
842-
{
843-
self::assertSame('-0123456789', Inline::parse('-0123456789'));
844-
}
845-
846827
public function testParseCommentNotPrefixedBySpaces()
847828
{
848829
self::assertSame('foo', Inline::parse('"foo"#comment'));

0 commit comments

Comments
 (0)