• 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

96.15
/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-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\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(
15✔
41
        private readonly View\TemplateRenderer $renderer,
42
    ) {
43
        $this->typo3Version = new Core\Information\Typo3Version();
15✔
44
    }
45

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

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

64
        return \preg_replace('/((?<!\n)\n(?!(\n|\d)))/', ' ', $prompt) ?? $prompt;
10✔
65
    }
66

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

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

79
        foreach ($applicationFrame->getSnippet(9) as $number => $line) {
10✔
80
            $snippet .= $number . ' ' . $line . PHP_EOL;
10✔
81
        }
82

83
        return \trim($snippet);
10✔
84
    }
85
}
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