-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[VarDumper] fix trailling comma when dumping an exception #24735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
37554f3
to
5ae1073
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More broadly: it only uses the trailing comma for actual arrays, which is what targeted the initial feature anyway. Not adding a trailing comma to each line.
👍
Not sure: as @lyrixx mentioned, the comma is needed when dumping on a single line. Then, it's also useful for objects, isn't it? |
Perhaps, but AFAIU, nested structures aren't dumped inlined, and that's probably not something we should target as it'll be pretty unreadable and useless to me. See format.php code#!/usr/bin/env php
<?php
use Symfony\Bridge\Monolog\Formatter\ConsoleFormatter;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\OptionsResolver\OptionsResolver;
require __DIR__.'/vendor/autoload.php';
$input = new ArgvInput(null, (new InputDefinition([new InputOption('multiline')])));
$formatter = new ConsoleFormatter(['multiline' => $input->getOption('multiline')]);
$std = new stdClass();
$std->foo = 123;
$std->bar = 'bar';
(new ConsoleOutput())->writeln($formatter->format([
'level' => 100,
'level_name' => 'info',
'message' => 'foo',
'datetime' => new \DateTime(),
'channel' => 'app',
'context' => [
'date' => new \DateTime(),
'opt' => new OptionsResolver(),
'std' => $std,
],
'extra' => [],
]));
10:46:31 info [app] foo ["date" => DateTime @1509270391 {date: 2017-10-29 10:46:31.987557 Europe/Zurich (+01:00)},"opt" => Symfony\Component\OptionsResolver\OptionsResolver { …},"std" => { …}] [] whereas 10:46:38 info [app] foo
[
"date" => DateTime @1509270398 {
date: 2017-10-29 10:46:38.564727 Europe/Zurich (+01:00)
},
"opt" => Symfony\Component\OptionsResolver\OptionsResolver {
-defined: []
-defaults: []
-required: []
-resolved: []
-normalizers: []
-allowedValues: []
-allowedTypes: []
-lazy: []
-calling: []
-locked: false
},
"std" => {
+"foo": 123
+"bar": "bar"
}
]
[] So IMHO it's okay. |
@@ -494,9 +495,10 @@ protected function dumpLine($depth, $endOfValue = false) | |||
|
|||
protected function endValue(Cursor $cursor) | |||
{ | |||
if (self::DUMP_TRAILING_COMMA & $this->flags && 0 < $cursor->depth) { | |||
$isStubArray = (Stub::ARRAY_INDEXED === $cursor->hashType || Stub::ARRAY_ASSOC === $cursor->hashType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be an "if" that wraps the other "if"s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WDYM?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
diff --git a/src/Symfony/Component/VarDumper/Dumper/CliDumper.php b/src/Symfony/Component/VarDumper/Dumper/CliDumper.php
index 48f9dc1108..5bf89112e6 100644
--- a/src/Symfony/Component/VarDumper/Dumper/CliDumper.php
+++ b/src/Symfony/Component/VarDumper/Dumper/CliDumper.php
@@ -526,11 +526,12 @@ class CliDumper extends AbstractDumper
protected function endValue(Cursor $cursor)
{
- $isStubArray = (Stub::ARRAY_INDEXED === $cursor->hashType || Stub::ARRAY_ASSOC === $cursor->hashType);
- if (self::DUMP_TRAILING_COMMA & $this->flags && 0 < $cursor->depth && $isStubArray) {
- $this->line .= ',';
- } elseif (self::DUMP_COMMA_SEPARATOR & $this->flags && 1 < $cursor->hashLength - $cursor->hashIndex && $isStubArray) {
- $this->line .= ',';
+ if (Stub::ARRAY_INDEXED === $cursor->hashType || Stub::ARRAY_ASSOC === $cursor->hashType) {
+ if (self::DUMP_TRAILING_COMMA & $this->flags && 0 < $cursor->depth) {
+ $this->line .= ',';
+ } elseif (self::DUMP_COMMA_SEPARATOR & $this->flags && 1 < $cursor->hashLength - $cursor->hashIndex) {
+ $this->line .= ',';
+ }
}
$this->dumpLine($cursor->depth, true);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ogizanagi, done @nicolas-grekas.
5ae1073
to
0456475
Compare
0456475
to
fc3fe7f
Compare
Thank you @Simperfit. |
…(Simperfit) This PR was merged into the 3.3 branch. Discussion ---------- [VarDumper] fix trailling comma when dumping an exception | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yesish | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #24581 | License | MIT | Doc PR | O This PR is fixing a behaviour when a exception got every single line with a comma. Commits ------- fc3fe7f [VarDumper] fix trailling comma when dumping an exception
This PR is fixing a behaviour when a exception got every single line with a comma.