Passed
Push — master ( 79b36b...0f8cd6 )
by Darko
10:13
created

SteamSearchGames::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 29
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 29
rs 9.6666
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Console\Commands;
6
7
use App\Models\SteamApp;
8
use App\Services\SteamService;
0 ignored issues
show
Bug introduced by
The type App\Services\SteamService was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Illuminate\Console\Command;
10
11
use function Laravel\Prompts\progress;
12
use function Laravel\Prompts\info;
13
use function Laravel\Prompts\warning;
14
use function Laravel\Prompts\table;
15
16
class SteamSearchGames extends Command
17
{
18
    /**
19
     * The name and signature of the console command.
20
     *
21
     * @var string
22
     */
23
    protected $signature = 'steam:search
24
                            {query : The search query}
25
                            {--limit=10 : Maximum number of results}';
26
27
    /**
28
     * The console command description.
29
     *
30
     * @var string
31
     */
32
    protected $description = 'Search for games in the local Steam database';
33
34
    /**
35
     * Execute the console command.
36
     */
37
    public function handle(SteamService $steamService): int
38
    {
39
        $query = $this->argument('query');
40
        $limit = (int) $this->option('limit');
41
42
        info("Searching for: {$query}");
43
44
        $results = $steamService->searchMultiple($query, $limit);
45
46
        if ($results->isEmpty()) {
47
            warning('No games found matching your query.');
48
            return Command::SUCCESS;
49
        }
50
51
        info("Found {$results->count()} result(s):");
52
53
        $tableData = $results->map(fn($r) => [
54
            $r['appid'],
55
            substr($r['name'], 0, 60),
56
            number_format($r['score'], 1) . '%',
57
            'https://store.steampowered.com/app/' . $r['appid'],
58
        ])->toArray();
59
60
        table(
61
            ['App ID', 'Name', 'Score', 'Store URL'],
62
            $tableData
63
        );
64
65
        return Command::SUCCESS;
66
    }
67
}
68
69