Skip to content

Commit 1d50bc1

Browse files
committed
Add comments explaining the purpose of int cast
1 parent 65ef80b commit 1d50bc1

3 files changed

Lines changed: 5 additions & 0 deletions

File tree

app/Http/Controllers/ConversionMetricController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,16 @@ public function index(Request $request) {
3434
$daysSinceLastEdit = null;
3535

3636
if ($wikiLastEditedTime !== null) {
37+
// Cast to int to avoid fractional-day values in CSV/JSON and keep cutoff logic predictable.
3738
$daysSinceLastEdit = (int) $wikiLastEditedTime->diffInDays($current_date, false);
3839
}
3940

4041
if ($daysSinceLastEdit !== null && $daysSinceLastEdit >= 90) {
42+
// Keep exported duration as whole days for stable reporting.
4143
$time_before_wiki_abandoned_days = (int) $wiki->created_at->diffInDays($wikiLastEditedTime, false);
4244
}
4345
if ($wikiFirstEditedTime !== null) {
46+
// Keep exported duration as whole days for stable reporting.
4447
$time_to_engage_days = (int) $wiki->created_at->diffInDays($wikiFirstEditedTime, false);
4548
}
4649
$wiki_number_of_editors = $wiki->wikiSiteStats()->first()['activeusers'] ?? null;

app/Jobs/PlatformStatsSummaryJob.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ public function prepareStats(array $allStats, $wikis): array {
132132
// is it edited in the last 90 days?
133133
if (!is_null($stats['lastEdit'])) {
134134
$lastTimestamp = MWTimestampHelper::getCarbonFromMWTimestamp(intval($stats['lastEdit']));
135+
// Carbon can return fractional seconds; cast to int so threshold checks use whole-second precision.
135136
$diff = (int) $lastTimestamp->diffInSeconds($currentTime, true);
136137

137138
if ($diff <= $this->inactiveThreshold) {

app/Jobs/SendEmptyWikiNotificationsJob.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function checkIfWikiIsOldAndEmpty(Wiki $wiki) {
3434
$emptyDaysThreshold = config('wbstack.wiki_empty_notification_threshold');
3535
$createdAt = $wiki->created_at;
3636
$now = CarbonImmutable::now();
37+
// Normalize to whole days so comparisons with the integer config threshold stay deterministic.
3738
$emptyWikiDays = (int) $createdAt->diffInDays($now, true);
3839

3940
$firstEdited = $wiki->wikiLifecycleEvents->first_edited;

0 commit comments

Comments
 (0)