Problem/Motivation
If there are no date ranges (due to some internal test), then the module does not check whether $start is NULL. Passing NULL into the \DateTime constructor is deprecated in PHP 8.1 and a warning will be thrown.
Deprecated function: DateTime::__construct(): Passing null to parameter #1 ($datetime) of type string is deprecated in Drupal\simplenews_stats\SimplenewsStatsPage->getDates() (line 369 of modules/contrib/simplenews_stats/src/SimplenewsStatsPage.php).
Drupal\simplenews_stats\SimplenewsStatsPage->getDates() (Line: 387)
Drupal\simplenews_stats\SimplenewsStatsPage->getDatesForCharts() (Line: 266)
Drupal\simplenews_stats\SimplenewsStatsPage->getpage() (Line: 55)
Drupal\simplenews_stats\Controller\SimplenewsStatsAdminController->stats(Object)
Steps to reproduce
- Install the module
- Create a new Newsletter issue node
- Click the Stats tab
Proposed resolution
When there is no data in the series or no series, also return empty. Or use the null coalesce operator to set a $start and $end to an empty string or 'now'.
Comments
Comment #3
mradcliffeComment #4
keshavv commentedI have gone through the issue and was able to reproduce it, Confirmed that there is an issue, and the given MR works well.
Moved to RTBC
Comment #7
damien laguerre commentedMerged, thanks!