8000 [Form] minor fixes in DateTime transformers by HeahDude · Pull Request #18548 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] minor fixes in DateTime transformers #18548

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

Closed
wants to merge 1 commit into from

Conversation

HeahDude
Copy link
Contributor
Q A
Branch? 2.3+
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets ~
License MIT
Doc PR ~

*/
public function transform($value)
public function transform($dateTime)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-1 for this renaming. It will make it harder to merge branches together for no real benefit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be fixed in a way to match the current name in the doc block, otherwise the doc block name should be changed. I did it so it's consistent with all the other DateTime transformers.

I don't understand why do you say it makes it harder to merge if it can be applied in all current maintained branches ?

@xabbuh
Copy link
Member
xabbuh commented Apr 14, 2016

Can you add a new test to prevent regressions?

@HeahDude
Copy link
Contributor Author

@xabbuh I'd like to, but there is no test for this exception in other transformers. I don't know how to make it fail. Any ideas ?

@HeahDude
Copy link
Contributor Author

After a deeper look into this, I don't understand why this try block is in all the other transformers since they all extend the BaseDateTimeTransformer which tests timezones in the constructor. If setTimeZone() fails it just return false. So shouldn't we test false before throwing instead ?

@HeahDude
Copy link
Contributor Author

@HeahDude HeahDude force-pushed the minor/form-cs_fixes branch from 7f3c1f1 to 24fd49f Compare April 14, 2016 18:12
@@ -58,12 +75,8 @@ public function reverseTransform($rfc3339)
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
}

if ($this->outputTimezone !== $dateTime->getTimezone()->getName()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if condition looks wrong, shouldn't it test the input's timezone ?

$dateTime = clone $dateTime;
if (!$dateTime instanceof \DateTimeImmutable) {
$dateTime = clone $dateTime;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should always clone to not modify the input data, shouldn't we?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xabbuh, I've no strong opinion on this. I just did it because I noticed DateTimeImmutable was not cloned in other transformers needing to clone the value, ref DateTimeToArrayTransformer and DateTimeToStringTransformer.

Should we change this behavior there too ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point is that the DataTransformerInterface just states that the given input should be transformed and then being returned. To me this does not include that the input is allowed to change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes even more sense when we consider that a DateTime object will be returned by reverseTransform() anyway, and actually it sets the output timezone on the input data...

So I guess I should change it in all three, thanks @xabbuh for pointing this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xabbuh technically, nothing was changing the input in the proposal. A DateTimeImmutable is immutable.

@HeahDude HeahDude force-pushed the minor/form-cs_fixes branch from 24fd49f to a35c28c Compare April 19, 2016 13:56
@HeahDude HeahDude force-pushed the minor/form-cs_fixes branch from a35c28c to d82c804 Compare April 19, 2016 14:20
@HeahDude
Copy link
Contributor Author

Ok updated after Stof's comment.

If you agree with this condition change, this one should be finished.

Thanks for the reviews.

@fabpot
Copy link
Member
fabpot commented Jun 15, 2016

Thank you @HeahDude.

fabpot added a commit that referenced this pull request Jun 15, 2016
This PR was submitted for the 2.3 branch but it was merged into the 2.7 branch instead (closes #18548).

Discussion
----------

[Form] minor fixes in DateTime transformers

| Q             | A
| ------------- | ---
| Branch?       | 2.3+
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | ~
| License       | MIT
| Doc PR        | ~

Commits
-------

b91008f [Form] fixed DateTime transformers
@fabpot fabpot closed this Jun 15, 2016
@HeahDude HeahDude deleted the minor/form-cs_fixes branch June 15, 2016 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0