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

eliashaeussler / typo3-solver / 13217441560

08 Feb 2025 04:36PM UTC coverage: 87.749% (-2.1%) from 89.843%
13217441560

push

github

web-flow
Merge pull request #289 from eliashaeussler/task/covers-class

[TASK] Add `#[CoversClass]` attributes to all tests

838 of 955 relevant lines covered (87.75%)

2.38 hits per line

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

88.46
/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
    ) {
43
        $this->typo3Version = new Core\Information\Typo3Version();
1✔
44
    }
45

46
    public static function create(): static
×
47
    {
48
        return new self(new View\TemplateRenderer());
×
49
    }
50

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

64
        return \preg_replace('/((?<!\n)\n(?!(\n|\d)))/', ' ', $prompt) ?? $prompt;
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
}
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