diff --git a/app/Commands/GamesCommand.php b/app/Commands/GamesCommand.php index 04fa511..307d159 100644 --- a/app/Commands/GamesCommand.php +++ b/app/Commands/GamesCommand.php @@ -8,16 +8,18 @@ class GamesCommand extends Command { - protected $signature = 'games'; + protected $signature = 'games + {--sports= : The sports you want to only want to show}'; public function handle(Scores $scores): void { + $sportsToShow = explode(',', $this->option('sports')); $updateInSeconds = 20; - $sports = $this->getScores(); + $sports = $this->getScores($sportsToShow); - live(function () use (&$updateInSeconds, &$sports) { + live(function () use (&$updateInSeconds, &$sports, $sportsToShow) { if ($updateInSeconds === 0) { - $sports = $this->getScores(); + $sports = $this->getScores($sportsToShow); $updateInSeconds = 20; } @@ -28,8 +30,11 @@ public function handle(Scores $scores): void })->refreshEvery(seconds: 1); } - private function getScores(): array + /** + * @param $sportsToShow string[] + */ + private function getScores(array $sportsToShow = []): array { - return (new Scores())->getScores(); + return (new Scores())->getScores($sportsToShow); } } diff --git a/app/Scores.php b/app/Scores.php index fb285af..10f8116 100644 --- a/app/Scores.php +++ b/app/Scores.php @@ -24,13 +24,21 @@ class Scores /** * Gets the Scores from the multiple sports available. * + * @param $sportsToShow string[] * @return array */ - public function getScores(): array + public function getScores(array $sportsToShow = []): array { $data = []; + $sports = self::$sportsAvailable; - foreach (self::$sportsAvailable as $sport => $class) { + $sportsToShow = array_filter($sportsToShow); + if ($sportsToShow !== []) { + $sports = collect(self::$sportsAvailable) + ->filter(fn ($class, $sport) => in_array($sport, $sportsToShow)); + } + + foreach ($sports as $sport => $class) { /** @var ScoresApi $class */ $data[$sport] = (new $class())->fetch(); } diff --git a/resources/views/components/sport-leagues.blade.php b/resources/views/components/sport-leagues.blade.php index 9481fe0..28540e5 100644 --- a/resources/views/components/sport-leagues.blade.php +++ b/resources/views/components/sport-leagues.blade.php @@ -15,5 +15,5 @@ @endforeach @empty -
There are no live games currently in progress
+
There are no live games currently in progress...
@endforelse