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

eliashaeussler / typo3-solver / 13272478878

11 Feb 2025 09:05PM UTC coverage: 88.036% (-0.1%) from 88.153%
13272478878

push

github

web-flow
Merge pull request #297 from eliashaeussler/feature/improve-prompt

[FEATURE] Improve default prompt and include DB version

8 of 11 new or added lines in 1 file covered. (72.73%)

883 of 1003 relevant lines covered (88.04%)

2.33 hits per line

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

84.85
/Classes/ProblemSolving/Solution/Prompt/DefaultPrompt.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-2025 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\ProblemSolving\Solution\Prompt;
25

26
use EliasHaeussler\Typo3Solver\View;
27
use Spatie\Backtrace;
28
use TYPO3\CMS\Core;
29

30
/**
31
 * DefaultPrompt.
32
 *
33
 * @author Elias Häußler <elias@haeussler.dev>
34
 * @license GPL-2.0-or-later
35
 */
36
final class DefaultPrompt implements Prompt
37
{
38
    private readonly Core\Information\Typo3Version $typo3Version;
39

40
    public function __construct(
1✔
41
        private readonly View\TemplateRenderer $renderer,
42
        private readonly Core\Database\ConnectionPool $connectionPool,
43
    ) {
44
        $this->typo3Version = new Core\Information\Typo3Version();
1✔
45
    }
46

47
    public static function create(): static
×
48
    {
NEW
49
        return new self(new View\TemplateRenderer(), new Core\Database\ConnectionPool());
×
50
    }
51

52
    public function generate(\Throwable $exception): string
1✔
53
    {
54
        return \trim(
1✔
55
            $this->renderer->render('Prompt/Default', [
1✔
56
                'exception' => $exception,
1✔
57
                'exceptionClass' => $exception::class,
1✔
58
                'snippet' => $this->createCodeSnippet($exception),
1✔
59
                'mode' => Core\Core\Environment::isComposerMode() ? 'composer-managed' : 'classic mode',
1✔
60
                'typo3Version' => $this->typo3Version->getVersion(),
1✔
61
                'phpVersion' => PHP_VERSION,
1✔
62
                'dbVersion' => $this->getDatabasePlatformAndVersion(),
1✔
63
            ]),
1✔
64
        );
1✔
65
    }
66

67
    private function createCodeSnippet(\Throwable $exception): string
1✔
68
    {
69
        $backtrace = Backtrace\Backtrace::createForThrowable($exception);
1✔
70
        $frames = $backtrace->frames();
1✔
71
        $applicationFrame = $frames[$backtrace->firstApplicationFrameIndex()] ?? null;
1✔
72
        $snippet = '';
1✔
73

74
        // Early return if application frame could not be determined
75
        if ($applicationFrame === null) {
1✔
76
            return $snippet;
×
77
        }
78

79
        /**
80
         * @var int $number
81
         * @var string $line
82
         */
83
        foreach ($applicationFrame->getSnippet(9) as $number => $line) {
1✔
84
            $snippet .= $number . ' ' . $line . PHP_EOL;
1✔
85
        }
86

87
        return \trim($snippet);
1✔
88
    }
89

90
    private function getDatabasePlatformAndVersion(): ?string
1✔
91
    {
92
        try {
93
            $connection = $this->connectionPool->getConnectionByName(
1✔
94
                Core\Database\ConnectionPool::DEFAULT_CONNECTION_NAME,
1✔
95
            );
1✔
NEW
96
        } catch (\Exception) {
×
NEW
97
            return null;
×
98
        }
99

100
        return $connection->getServerVersion();
1✔
101
    }
102
}
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

© 2025 Coveralls, Inc