-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[VarDumper] Add interval caster #23357
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
First proposal:
|
|
||
public static function castInterval(\DateInterval $i, array $a, Stub $stub, $isNested, $filter) | ||
{ | ||
$prefix = Caster::PREFIX_VIRTUAL; |
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.
no need to define a variable, as it is used only once
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.
Fixed
.($i->d ? '%dd ' : '') | ||
; | ||
|
||
if (PHP_VERSION_ID >= 70100) { |
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.
please use \PHP_VERSION_ID
, to let the version comparison be applied at compile time (not qualifying the constant requires doing it at runtime to check the constant first in the current namespace)
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.
\
added
|
||
public function provideIntervals() | ||
{ | ||
$ms = function () { return PHP_VERSION_ID >= 70100 ? '.000000' : ''; }; |
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.
no need to use a function. Use a simple variable, as this is purely static.
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.
Updated
00552e1
to
fcafa3a
Compare
I agree with @nicolas-grekas's original comment (#22431 (comment)), so I'm not convinced by the new suggested output. Also, why showing the Would it be interesting to also output it as the time_interval spec? WDYT? |
Thank you for your thoughts @ogizanagi. I would say this:
|
Just quoting @nicolas-grekas:
I'm using psysh quite often, to quickly test or demonstrate things, and despite built-in introspection/doc commands like |
Same opinion as @ogizanagi. |
fcafa3a
to
79e7909
Compare
"normal" should display all existing properties, even undocumented ones. Also, why keep "days" in compact mode? |
79e7909
to
1971d78
Compare
It's updated: "normal" displays all, and only |
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.
with some suggestions
/** | ||
* @dataProvider provideIntervals | ||
*/ | ||
public function testCastInterval($interval_spec, $invert, $expected) |
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 $intervalSpec
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.
Fixed (in official doc, this argument is named $interval_spec
).
|
||
public static function castInterval(\DateInterval $interval, array $a, Stub $stub, $isNested, $filter) | ||
{ | ||
$i = array(Caster::PREFIX_VIRTUAL.'interval' => self::formatInterval($interval)); |
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.
what about using a ConstStub here that gives the number of seconds on hover (html mode):
new ConstStub(self::formatInterval($interval), $numberOfSeconds);
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.
Good idea. Number of seconds added.
a123ea0
to
2a64de6
Compare
How to fix kind of HHVM failure?
|
diff --git a/src/Symfony/Component/VarDumper/Caster/DateCaster.php b/src/Symfony/Component/VarDumper/Caster/DateCaster.php
index c9edc10..1ecd962 100644
--- a/src/Symfony/Component/VarDumper/Caster/DateCaster.php
+++ b/src/Symfony/Component/VarDumper/Caster/DateCaster.php
@@ -58,7 +58,7 @@ class DateCaster
.($i->d ? '%dd ' : '')
;
- if (\PHP_VERSION_ID >= 70100) {
+ if (isset($i->f)) {
$format .= $i->h || $i->i || $i->s || $i->f ? '%H:%I:%S.%F' : '';
} else {
$format .= $i->h || $i->i || $i->s ? '%H:%I:%S' : '';
diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/DateCasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/DateCasterTest.php
index 9db333e..c4c1263 100644
--- a/src/Symfony/Component/VarDumper/Tests/Caster/DateCasterTest.php
+++ b/src/Symfony/Component/VarDumper/Tests/Caster/DateCasterTest.php
@@ -97,8 +97,7 @@ EODUMP;
$xDump = <<<EODUMP
DateInterval {
interval: $expected
-%a
-}
+%A}
EODUMP;
$this->assertDumpMatchesFormat($xDump, $interval);
@@ -162,7 +161,8 @@ EODUMP;
public function provideIntervals()
{
- $ms = \PHP_VERSION_ID >= 70100 ? '.000000' : '';
+ $interval = new \DateInterval('PT0S');
+ $ms = isset($interval->f);
return array(
array('PT0S', 0, '0s', '0s'), |
2a64de6
to
95a51e7
Compare
Mmh, |
but my HHVM fails when PHP_VERSION_ID is used... |
you should report the notice as a bug I guess |
using both PHP_VERSION_ID and the isset check should do it |
264e264
to
ee7bcf5
Compare
There was no error related with |
|
that's because the behavior of hhvm changes from version to version and Travis doesn't have the latest. But trust me, this check is not enough, you need the isset one also :) |
(or install hhvm to see by yourself ;) ) |
ee7bcf5
to
a73522c
Compare
Updated: used |
Time to merge? :) |
Thank you @maidmaid. |
This PR was merged into the 3.4 branch. Discussion ---------- [VarDumper] Add interval caster | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | / | License | MIT | Doc PR | / cf #22431 (comment) Commits ------- a73522c Add interval caster
…interval caster (maidmaid) This PR was merged into the 4.0-dev branch. Discussion ---------- [VarDumper] Remove low PHP version and hhvm compat in interval caster | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | yes | Deprecations? | no | Tests pass? | yes | Fixed tickets | #23357 (comment) | License | MIT | Doc PR | / Commits ------- ccca65b Remove hhvm compat
cf #22431 (comment)