• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

eliashaeussler / typo3-solver / 10780070405

09 Sep 2024 07:38PM UTC coverage: 87.159%. Remained the same
10780070405

Pull #258

github

web-flow
[TASK] Update eslint-plugin-sonarjs to v2

| datasource | package               | from  | to    |
| ---------- | --------------------- | ----- | ----- |
| npm        | eslint-plugin-sonarjs | 1.0.4 | 2.0.2 |
Pull Request #258: [TASK] Update eslint-plugin-sonarjs to v2

862 of 989 relevant lines covered (87.16%)

6.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/Classes/Command/ListModelsCommand.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the TYPO3 CMS extension "solver".
7
 *
8
 * Copyright (C) 2023-2024 Elias Häußler <elias@haeussler.dev>
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation, either version 2 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22
 */
23

24
namespace EliasHaeussler\Typo3Solver\Command;
25

26
use OpenAI\Client;
27
use OpenAI\Responses;
28
use Symfony\Component\Console;
29

30
/**
31
 * ListModelsCommand
32
 *
33
 * @author Elias Häußler <elias@haeussler.dev>
34
 * @license GPL-2.0-or-later
35
 */
36
final class ListModelsCommand extends Console\Command\Command
37
{
38
    public function __construct(
2✔
39
        private readonly Client $client,
40
    ) {
41
        parent::__construct('solver:list-models');
2✔
42
    }
43

44
    protected function configure(): void
2✔
45
    {
46
        $this->addOption(
2✔
47
            'all',
2✔
48
            'a',
2✔
49
            Console\Input\InputOption::VALUE_NONE,
2✔
50
            'List all available models, even those which cannot be used',
2✔
51
        );
2✔
52
    }
53

54
    protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int
2✔
55
    {
56
        $io = new Console\Style\SymfonyStyle($input, $output);
2✔
57
        $listAll = $input->getOption('all');
2✔
58

59
        // Retrieve all available models
60
        $modelListResponse = $this->client->models()->list()->data;
2✔
61

62
        if ($listAll) {
2✔
63
            $io->title('Available OpenAI models');
1✔
64
        } else {
65
            $io->title('Available GPT models');
1✔
66

67
            // Filter by GPT models
68
            $modelListResponse = \array_filter($modelListResponse, $this->isGPTModel(...));
1✔
69
        }
70

71
        // Map responses to model IDs
72
        $models = \array_map(
2✔
73
            $this->decorateModel(...),
2✔
74
            $modelListResponse,
2✔
75
        );
2✔
76

77
        \sort($models);
2✔
78

79
        $io->listing($models);
2✔
80

81
        if ($listAll) {
2✔
82
            $io->writeln('💡 <comment>Only GPT models can be used with this extension.</comment>');
1✔
83
            $io->newLine();
1✔
84
        }
85

86
        return self::SUCCESS;
2✔
87
    }
88

89
    private function isGPTModel(Responses\Models\RetrieveResponse $response): bool
1✔
90
    {
91
        return \str_starts_with(\strtolower($response->id), 'gpt-');
1✔
92
    }
93

94
    private function decorateModel(Responses\Models\RetrieveResponse $response): string
2✔
95
    {
96
        return \sprintf('%s <fg=gray>(created at %s)</>', $response->id, \date('d/m/Y', $response->created));
2✔
97
    }
98
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc