diff --git a/Module.php b/Module.php index a3c62a4..9c77670 100644 --- a/Module.php +++ b/Module.php @@ -92,17 +92,13 @@ private static function permissionInstances(array $classes): array public function getAdapterRegistry(): AdapterRegistry { - if ($this->adapterRegistry === null) { - $this->adapterRegistry = AdapterRegistry::createDefault(); - } + $this->adapterRegistry ??= AdapterRegistry::createDefault(); return $this->adapterRegistry; } public function getSpecialBetTypeRegistry(): SpecialBetTypeRegistry { - if ($this->specialBetTypeRegistry === null) { - $this->specialBetTypeRegistry = SpecialBetTypeRegistry::createDefault(); - } + $this->specialBetTypeRegistry ??= SpecialBetTypeRegistry::createDefault(); return $this->specialBetTypeRegistry; } diff --git a/adapters/FootballDataOrgAdapter.php b/adapters/FootballDataOrgAdapter.php index 2f4d7b2..47886b7 100644 --- a/adapters/FootballDataOrgAdapter.php +++ b/adapters/FootballDataOrgAdapter.php @@ -171,9 +171,7 @@ private function syncTeams(Competition $competition, array $teamsData, SyncRepor } $team = Team::findByExternalId(self::KEY, $externalId); $isNew = $team === null; - if ($team === null) { - $team = new Team(); - } + $team ??= new Team(); $team->name = (string) ($teamData['name'] ?? $team->name ?? 'Unknown'); $team->short_name = $teamData['tla'] ?? $teamData['shortName'] ?? $team->short_name; $team->country_code = $teamData['area']['code'] ?? $team->country_code; diff --git a/adapters/HumHubApiAdapter.php b/adapters/HumHubApiAdapter.php index bef3a36..ed24d03 100644 --- a/adapters/HumHubApiAdapter.php +++ b/adapters/HumHubApiAdapter.php @@ -209,9 +209,7 @@ private function applyTeams(Competition $competition, array $teamsData, SyncRepo } $team = Team::findByExternalId(self::KEY, $externalId); $isNew = $team === null; - if ($team === null) { - $team = new Team(); - } + $team ??= new Team(); $team->name = (string) ($teamData['name'] ?? $team->name ?? 'Unknown'); $team->short_name = $teamData['short_name'] ?? $team->short_name; $team->country_code = $teamData['country_code'] ?? $team->country_code; diff --git a/adapters/MockAdapter.php b/adapters/MockAdapter.php index 5f003f8..eae4403 100644 --- a/adapters/MockAdapter.php +++ b/adapters/MockAdapter.php @@ -124,13 +124,13 @@ public function syncResults(Competition $competition): SyncReport foreach ($scheduled as $game) { $elapsed = $now - (KickoffTime::parse($game->kickoff_at) ?? $now); if ($elapsed > self::LIVE_WINDOW_SEC) { - $game->home_score = $game->home_score ?? random_int(0, 4); - $game->away_score = $game->away_score ?? random_int(0, 4); + $game->home_score ??= random_int(0, 4); + $game->away_score ??= random_int(0, 4); $game->status = Game::STATUS_FINISHED; $game->current_minute = null; } else { - $game->home_score = $game->home_score ?? 0; - $game->away_score = $game->away_score ?? 0; + $game->home_score ??= 0; + $game->away_score ??= 0; $game->status = Game::STATUS_LIVE; $game->current_minute = $this->mockMatchMinute($elapsed); } @@ -404,9 +404,7 @@ protected function computeGroupStandings(Competition $competition): array foreach ($games as $g) { $group = (string) $g->group_label; foreach ([$g->home_team_id, $g->away_team_id] as $tid) { - if (!isset($stats[$group][$tid])) { - $stats[$group][$tid] = ['points' => 0, 'diff' => 0, 'for' => 0]; - } + $stats[$group][$tid] ??= ['points' => 0, 'diff' => 0, 'for' => 0]; } $hs = (int) $g->home_score; $as = (int) $g->away_score; diff --git a/controllers/CompetitionController.php b/controllers/CompetitionController.php index bb67069..ee916d1 100644 --- a/controllers/CompetitionController.php +++ b/controllers/CompetitionController.php @@ -217,11 +217,9 @@ private function shouldDefaultToBonus(array $openSpecialBets, int $userId): bool private function pickDefaultMatchday(array $entries): ?string { - $isDated = function (array $entry): bool { - return $entry['games'] !== [] - && empty($entry['isPlaceholder']) - && empty($entry['isBonus']); - }; + $isDated = (fn(array $entry): bool => $entry['games'] !== [] + && empty($entry['isPlaceholder']) + && empty($entry['isBonus'])); // Earliest matchday that still has at least one game whose kickoff is // in the future — i.e. the next-best one the user can still tip. @@ -382,7 +380,7 @@ public function actionUserHistory($slug, $userId, $page = 1) $page = max(1, (int) $page); $baseTipQuery = Tip::find() - ->joinWith(['game' => function ($q) use ($competition) { + ->joinWith(['game' => function ($q) use ($competition): void { $q->andWhere(['kickoff_game.competition_id' => $competition->id]); }]) ->andWhere(['user_id' => $targetUserId]) @@ -408,7 +406,7 @@ public function actionUserHistory($slug, $userId, $page = 1) // Weltmeister/group-winner tip — the view filters by points in PHP, but // defense in depth says filter at the source. $specialBetTips = SpecialBetTip::find() - ->joinWith(['specialBet' => function ($q) use ($competition) { + ->joinWith(['specialBet' => function ($q) use ($competition): void { $q->andWhere(['kickoff_special_bet.competition_id' => $competition->id]); }]) ->andWhere(['user_id' => $targetUserId]) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index f3bfea2..107c0a4 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,6 +1,10 @@ Changelog ========= +1.0.17 (Unreleased) +------------------- +- Enh: Automated code refactoring for HumHub 1.18 using Rector + 1.0.16 (June 30, 2026) ---------------------- - Fix: Knockout matches decided in extra time or a penalty shootout were scored and shown against the wrong result. football-data.org's `fullTime` score is the cumulative final — it already includes extra-time goals and the penalty shootout — and is not the score after 90 minutes, so with the default "after 90 minutes" knockout scoring tips were wrongly scored against the extra-time/penalty result. The 90-minute score (the API's `regularTime`) is now used for scoring, the end-of-extra-time score is stored correctly (previously it held only the goals scored within extra time), and existing games are re-synced automatically on the next hourly cron after the update — no manual sync needed. diff --git a/module.json b/module.json index 43f387d..63fb368 100644 --- a/module.json +++ b/module.json @@ -10,7 +10,7 @@ "world cup", "leaderboard" ], - "version": "1.0.16", + "version": "1.0.17", "humhub": { "minVersion": "1.18" }, @@ -20,7 +20,7 @@ "name": "Lucas Bartholemy" }, { - "name": "Jörg Winne" + "name": "J\u00f6rg Winne" } ], "screenshots": [ @@ -32,4 +32,4 @@ "resources/screen6.png", "resources/screen7.png" ] -} +} \ No newline at end of file diff --git a/services/GroupStandings.php b/services/GroupStandings.php index a97968f..6f77300 100644 --- a/services/GroupStandings.php +++ b/services/GroupStandings.php @@ -22,9 +22,7 @@ public static function ranked(array $results): array $stats = []; foreach ($results as $r) { foreach ([$r['home'], $r['away']] as $tid) { - if (!isset($stats[$tid])) { - $stats[$tid] = ['teamId' => $tid, 'points' => 0, 'diff' => 0, 'for' => 0]; - } + $stats[$tid] ??= ['teamId' => $tid, 'points' => 0, 'diff' => 0, 'for' => 0]; } $hs = (int) $r['homeScore']; $as = (int) $r['awayScore']; diff --git a/services/LeaderboardService.php b/services/LeaderboardService.php index 62604e7..6782272 100644 --- a/services/LeaderboardService.php +++ b/services/LeaderboardService.php @@ -12,8 +12,8 @@ class LeaderboardService { - private Competition $competition; - private ScoringScheme $scheme; + private readonly Competition $competition; + private readonly ScoringScheme $scheme; public function __construct(Competition $competition) { diff --git a/services/MatchdayBonusService.php b/services/MatchdayBonusService.php index 96b9320..f710087 100644 --- a/services/MatchdayBonusService.php +++ b/services/MatchdayBonusService.php @@ -32,14 +32,11 @@ class MatchdayBonusService { public const BUCKET_BONUS = 'bonus'; + private readonly int $bonusPoints; - private Competition $competition; - private int $bonusPoints; - - public function __construct(Competition $competition) + public function __construct(private readonly Competition $competition) { - $this->competition = $competition; - $scheme = $competition->scoringScheme; + $scheme = $this->competition->scoringScheme; $this->bonusPoints = $scheme !== null ? (int) $scheme->matchday_winner_points : 0; } diff --git a/services/ScoringService.php b/services/ScoringService.php index dcaf10c..067a8b6 100644 --- a/services/ScoringService.php +++ b/services/ScoringService.php @@ -12,8 +12,8 @@ class ScoringService { - private Competition $competition; - private ScoringScheme $scheme; + private readonly Competition $competition; + private readonly ScoringScheme $scheme; public function __construct(Competition $competition) { diff --git a/views/competition/_detail_modal.php b/views/competition/_detail_modal.php index 7c6a11f..5343291 100644 --- a/views/competition/_detail_modal.php +++ b/views/competition/_detail_modal.php @@ -6,7 +6,7 @@ * Reused for user-history, match-tips and their pagination links. */ -$modalJs = << block is emitted at most once even if the partial // gets rendered twice in a single page (e.g. nested layouts). $this->registerJs($modalJs, \yii\web\View::POS_END, 'kickoff-detail-modal'); diff --git a/views/competition/_match_card.php b/views/competition/_match_card.php index 54467f8..132a5b0 100644 --- a/views/competition/_match_card.php +++ b/views/competition/_match_card.php @@ -13,7 +13,7 @@ /** @var \humhub\modules\kickoff\models\Competition $competition */ /** @var bool $preview Render only the part above the footer (no dashed-line footer). */ -$preview = $preview ?? false; +$preview ??= false; $home = $game->homeTeam; $away = $game->awayTeam; @@ -30,8 +30,8 @@ $displayHomeScore = $ruleScore[0] ?? $game->home_score; $displayAwayScore = $ruleScore[1] ?? $game->away_score; if ($isLive) { - $displayHomeScore = $displayHomeScore ?? 0; - $displayAwayScore = $displayAwayScore ?? 0; + $displayHomeScore ??= 0; + $displayAwayScore ??= 0; } $hasDisplayScore = $displayHomeScore !== null && $displayAwayScore !== null; // Live and finished games both render the score in a big, prominent block diff --git a/views/competition/rules.php b/views/competition/rules.php index 63e6773..e0b07a5 100644 --- a/views/competition/rules.php +++ b/views/competition/rules.php @@ -13,13 +13,11 @@ $this->registerAssetBundle(\humhub\modules\kickoff\assets\Assets::class); -$specialBetTypeLabel = function (string $type): string { - return match ($type) { - SpecialBet::TYPE_WINNER => Yii::t('KickoffModule.base', 'Tournament winner'), - SpecialBet::TYPE_GROUP_WINNER => Yii::t('KickoffModule.base', 'Group winner'), - default => ucfirst($type), - }; -}; +$specialBetTypeLabel = (fn(string $type): string => match ($type) { + SpecialBet::TYPE_WINNER => Yii::t('KickoffModule.base', 'Tournament winner'), + SpecialBet::TYPE_GROUP_WINNER => Yii::t('KickoffModule.base', 'Group winner'), + default => ucfirst($type), +}); ?>