Skip to content

Fix: Do not pass null to function that expects DateTime or string #869

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

Merged
merged 1 commit into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion eol.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<?php foreach (get_eol_branches() as $major => $branches): ?>
<?php foreach ($branches as $branch => $detail): ?>
<?php $eolDate = get_branch_security_eol_date($branch) ?>
<?php $eolPeriod = format_interval($eolDate, null) ?>
<?php $eolPeriod = format_interval($eolDate, new DateTime('now')) ?>
<tr>
<td><?php echo htmlspecialchars($branch); ?></td>
<td>
Expand Down
5 changes: 2 additions & 3 deletions include/branches.inc
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ $BRANCHES = [
* page. (Currently 28 days.) */
$KEEP_EOL = new DateInterval('P28D');

function format_interval($from, $to) {
function format_interval($from, DateTime $to) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alternatively, we could create $to in the function, but that would make it harder to test if we wanted to test it.

try {
$from_obj = $from instanceof DateTime ? $from : new DateTime($from);
$to_obj = $to instanceof DateTime ? $to : new DateTime($to);
$diff = $to_obj->diff($from_obj);
$diff = $to->diff($from_obj);

$times = [];
if ($diff->y) {
Expand Down
7 changes: 4 additions & 3 deletions supported-versions.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
$initial = get_branch_release_date($branch);
$until = get_branch_bug_eol_date($branch);
$eol = get_branch_security_eol_date($branch);
$now = new DateTime('now');
?>
<tr class="<?php echo $state ?>">
<td>
Expand All @@ -63,11 +64,11 @@
<?php endif ?>
</td>
<td><?php echo htmlspecialchars($initial->format('j M Y')) ?></td>
<td class="collapse-phone"><em><?php echo htmlspecialchars(format_interval($initial, null)) ?></em></td>
<td class="collapse-phone"><em><?php echo htmlspecialchars(format_interval($initial, $now)) ?></em></td>
<td><?php echo htmlspecialchars($until->format('j M Y')) ?></td>
<td class="collapse-phone"><em><?php echo htmlspecialchars(format_interval($until, null)) ?></em></td>
<td class="collapse-phone"><em><?php echo htmlspecialchars(format_interval($until, $now)) ?></em></td>
<td><?php echo htmlspecialchars($eol->format('j M Y')) ?></td>
<td class="collapse-phone"><em><?php echo htmlspecialchars(format_interval($eol, null)) ?></em></td>
<td class="collapse-phone"><em><?php echo htmlspecialchars(format_interval($eol, $now)) ?></em></td>
</tr>
<?php endforeach ?>
<?php endforeach ?>
Expand Down