Skip to content
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

Update ResetPasswordToken.php #225

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Model/ResetPasswordToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ public function getExpiresAtIntervalInstance(): \DateInterval
}

$createdAtTime = \DateTimeImmutable::createFromFormat('U', (string) $this->generatedAt);
$expiresAt = \DateTimeImmutable::createFromFormat('U', (string) $this->expiresAt->getTimestamp());

return $this->expiresAt->diff($createdAtTime);
return $expiresAt->diff($createdAtTime);
Comment on lines +142 to +144
Copy link
Collaborator

@jrushlow jrushlow Sep 27, 2022

Choose a reason for hiding this comment

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

I'm not 100% sure this is the best way to fix this "bug". Two things come to mind when I'm looking at this.

  1. What version of PHP are you using that you're getting an incorrect DateInterval instance? PHP 8.1 through 8.1.9 have several bugs related to diff'ing DateTime instances that were fixed in PHP 8.1.10.

  2. If we have to create a new expires at instance to get a "correct" interval, why not just fix the existing $expiresAt instance that is set in the constructor? Meaning, if we are instantiating that instance incorrectly, we should fix it at the source. (e.g. MakerBundle)

I would think that for the users who are using this bundle on its own, this change would be a BC because when they call ResetPasswordToken::getExpiresAt() the \DateTimeImuttable instance returned would not be "compatible" w/ the \DateInterval instance they are getting from this method.

Copy link
Member

Choose a reason for hiding this comment

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

  1. Hm, good question about the PHP version, it might be related to that known bug, so maybe it does not a problem on 8.1.10 anymore? If so, then all you need to do is to upgrade your PHP version.

  2. I probably missed the fact that the $expiresAt is instantiated in the Maker bundle. If so - it makes sense to fix it there instead

}

private function triggerDeprecation(): void
Expand Down