Skip to content

Commit bd0603d

Browse files
committed
bug #23108 [Yaml] Remove line number in deprecation notices (nicolas-grekas)
This PR was merged into the 3.3 branch. Discussion ---------- [Yaml] Remove line number in deprecation notices | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - While moving an app to 3.3, I noticed that my deprecation log is full of deprecation notices that differ only by some line number, but don't tell which file is concerned. This makes the line number useless, and just prevents aggregation. ![capture du 2017-06-08 16-29-31](https://user-images.githubusercontent.com/243674/26933795-dd123476-4c67-11e7-8cf3-406bedab9130.png) Commits ------- f82b618 [Yaml] Remove line number in deprecation notices
2 parents 99573dc + f82b618 commit bd0603d

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/Symfony/Component/Yaml/Inline.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
493493
if (!(Yaml::PARSE_KEYS_AS_STRINGS & $flags)) {
494494
$evaluatedKey = self::evaluateScalar($key, $flags, $references);
495495

496-
if ('' !== $key && $evaluatedKey !== $key && !is_string($evaluatedKey)) {
496+
if ('' !== $key && $evaluatedKey !== $key && !is_string($evaluatedKey) && !is_int($evaluatedKey)) {
497497
@trigger_error('Implicit casting of incompatible mapping keys to strings is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRING flag to explicitly enable the type casts.', E_USER_DEPRECATED);
498498
}
499499
}
@@ -519,7 +519,7 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
519519
// Parser cannot abort this mapping earlier, since lines
520520
// are processed sequentially.
521521
if (isset($output[$key])) {
522-
@trigger_error(sprintf('Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key, self::$parsedLineNumber + 1), E_USER_DEPRECATED);
522+
@trigger_error(sprintf('Duplicate key "%s" detected whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key), E_USER_DEPRECATED);
523523
$duplicate = true;
524524
}
525525
break;
@@ -530,7 +530,7 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
530530
// Parser cannot abort this mapping earlier, since lines
531531
// are processed sequentially.
532532
if (isset($output[$key])) {
533-
@trigger_error(sprintf('Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key, self::$parsedLineNumber + 1), E_USER_DEPRECATED);
533+
@trigger_error(sprintf('Duplicate key "%s" detected whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key), E_USER_DEPRECATED);
534534
$duplicate = true;
535535
}
536536
break;
@@ -540,7 +540,7 @@ private static function parseMapping($mapping, $flags, &$i = 0, $references = ar
540540
// Parser cannot abort this mapping earlier, since lines
541541
// are processed sequentially.
542542
if (isset($output[$key])) {
543-
@trigger_error(sprintf('Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key, self::$parsedLineNumber + 1), E_USER_DEPRECATED);
543+
@trigger_error(sprintf('Duplicate key "%s" detected whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key), E_USER_DEPRECATED);
544544
$duplicate = true;
545545
}
546546
--$i;

src/Symfony/Component/Yaml/Parser.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ private function doParse($value, $flags)
236236
throw $e;
237237
}
238238

239-
if (!(Yaml::PARSE_KEYS_AS_STRINGS & $flags) && !is_string($key)) {
240-
$keyType = is_numeric($key) ? 'numeric key' : 'incompatible key type';
241-
@trigger_error(sprintf('Implicit casting of %s to string on line %d is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRING flag to explicitly enable the type casts.', $keyType, $this->getRealCurrentLineNb()), E_USER_DEPRECATED);
239+
if (!(Yaml::PARSE_KEYS_AS_STRINGS & $flags) && !is_string($key) && !is_int($key)) {
240+
$keyType = is_numeric($key) ? 'numeric key' : 'non-string key';
241+
@trigger_error(sprintf('Implicit casting of %s to string is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRING flag to explicitly enable the type casts.', $keyType), E_USER_DEPRECATED);
242242
}
243243

244244
// Convert float keys to strings, to avoid being converted to integers by PHP
@@ -312,7 +312,7 @@ private function doParse($value, $flags)
312312
$data[$key] = null;
313313
}
314314
} else {
315-
@trigger_error(sprintf('Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key, $this->getRealCurrentLineNb() + 1), E_USER_DEPRECATED);
315+
@trigger_error(sprintf('Duplicate key "%s" detected whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key), E_USER_DEPRECATED);
316316
}
317317
} else {
318318
// remember the parsed line number here in case we need it to provide some contexts in error messages below
@@ -327,7 +327,7 @@ private function doParse($value, $flags)
327327
$data[$key] = $value;
328328
}
329329
} else {
330-
@trigger_error(sprintf('Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key, $realCurrentLineNbKey + 1), E_USER_DEPRECATED);
330+
@trigger_error(sprintf('Duplicate key "%s" detected whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key), E_USER_DEPRECATED);
331331
}
332332
}
333333
} else {
@@ -337,7 +337,7 @@ private function doParse($value, $flags)
337337
if ($allowOverwrite || !isset($data[$key])) {
338338
$data[$key] = $value;
339339
} else {
340-
@trigger_error(sprintf('Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key, $this->getRealCurrentLineNb() + 1), E_USER_DEPRECATED);
340+
@trigger_error(sprintf('Duplicate key "%s" detected whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key), E_USER_DEPRECATED);
341341
}
342342
}
343343
if ($isRef) {

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ public function testMappingDuplicateKeyFlow()
853853
/**
854854
* @group legacy
855855
* @dataProvider getParseExceptionOnDuplicateData
856-
* @expectedDeprecation Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated %s.
856+
* @expectedDeprecation Duplicate key "%s" detected whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated %s.
857857
* throws \Symfony\Component\Yaml\Exception\ParseException in 4.0
858858
*/
859859
public function testParseExceptionOnDuplicate($input, $duplicateKey, $lineNumber)
@@ -1081,7 +1081,7 @@ public function testYamlDirective()
10811081

10821082
/**
10831083
* @group legacy
1084-
* @expectedDeprecation Implicit casting of numeric key to string on line 1 is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRING flag to explicitly enable the type casts.
1084+
* @expectedDeprecation Implicit casting of numeric key to string is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRING flag to explicitly enable the type casts.
10851085
*/
10861086
public function testFloatKeys()
10871087
{
@@ -1103,7 +1103,7 @@ public function testFloatKeys()
11031103

11041104
/**
11051105
* @group legacy
1106-
* @expectedDeprecation Implicit casting of incompatible key type to string on line 1 is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRING flag to explicitly enable the type casts.
1106+
* @expectedDeprecation Implicit casting of non-string key to string is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Pass the PARSE_KEYS_AS_STRING flag to explicitly enable the type casts.
11071107
*/
11081108
public function testBooleanKeys()
11091109
{

0 commit comments

Comments
 (0)