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

eliashaeussler / typo3-solver / 30207885041

26 Jul 2026 03:17PM UTC coverage: 88.0%. Remained the same
30207885041

push

github

web-flow
Merge pull request #586 from eliashaeussler/task/cs

[TASK] Update to typo3/coding-standards 0.9.0

66 of 69 new or added lines in 24 files covered. (95.65%)

902 of 1025 relevant lines covered (88.0%)

2.31 hits per line

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

32.14
/Classes/Middleware/SolutionMiddleware.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-2026 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\Middleware;
25

26
use EliasHaeussler\SSE;
27
use EliasHaeussler\Typo3Solver\Authentication;
28
use EliasHaeussler\Typo3Solver\Cache;
29
use EliasHaeussler\Typo3Solver\Configuration;
30
use EliasHaeussler\Typo3Solver\Exception;
31
use EliasHaeussler\Typo3Solver\Formatter;
32
use EliasHaeussler\Typo3Solver\ProblemSolving;
33
use EliasHaeussler\Typo3Solver\Utility;
34
use Psr\Http\Message;
35
use Psr\Http\Server;
36
use TYPO3\CMS\Core;
37

38
/**
39
 * SolutionMiddleware
40
 *
41
 * @author Elias Häußler <elias@haeussler.dev>
42
 * @license GPL-2.0-or-later
43
 */
44
final readonly class SolutionMiddleware implements Server\MiddlewareInterface
45
{
46
    public const ROUTE_PATH = '/tx_solver/solution';
47

48
    public function __construct(
2✔
49
        private Configuration\Configuration $configuration,
50
        private Cache\ExceptionsCache $exceptionsCache,
51
        private Formatter\Message\ExceptionStreamFormatter $exceptionFormatter,
52
        private Formatter\WebStreamFormatter $webFormatter,
53
        private Authentication\StreamAuthentication $authentication,
54
    ) {}
2✔
55

56
    /**
57
     * @throws SSE\Exception\StreamIsActive
58
     * @throws SSE\Exception\StreamIsClosed
59
     * @throws SSE\Exception\StreamIsInactive
60
     * @throws \JsonException
61
     */
62
    public function process(
2✔
63
        Message\ServerRequestInterface $request,
64
        Server\RequestHandlerInterface $handler,
65
    ): Message\ResponseInterface {
66
        // Pass through request if it's not supported
67
        if (!$this->isRequestSupported($request)) {
2✔
68
            return $handler->handle($request);
2✔
69
        }
70

71
        // Create event stream
72
        $eventStream = SSE\Stream\SelfEmittingEventStream::create();
×
73
        $eventStream->open();
×
74

75
        try {
76
            // Get exception identifier and stream hash
77
            $hash = $request->getQueryParams()['hash'] ?? null;
×
78
            $id = $request->getQueryParams()['exception'] ?? null;
×
79

80
            // Throw exception if stream hash is invalid
NEW
81
            if (!is_string($hash)) {
×
82
                throw Exception\AuthenticationFailureException::create();
×
83
            }
84

85
            // Authenticate with stream hash
86
            $this->authentication->authenticate($hash);
×
87

88
            // Throw exception if exception identifier is invalid
NEW
89
            if (!is_string($id)) {
×
90
                throw Exception\UnrecoverableExceptionException::forMissingIdentifier();
×
91
            }
92

93
            // Restore exception
94
            $exception = $this->exceptionsCache->get($id);
×
95

96
            // Throw exception if original exception cannot be restored
97
            if ($exception === null) {
×
98
                throw Exception\UnrecoverableExceptionException::create($id);
×
99
            }
100

101
            // Create solver
102
            $solver = new ProblemSolving\Solver($this->configuration, $this->webFormatter);
×
103

104
            // Send solution stream
105
            foreach ($solver->solveStreamed($exception) as $solution) {
×
106
                $eventStream->sendMessage('solutionDelta', $solution);
×
107
            }
108
        } catch (\Throwable $exception) {
×
109
            $eventStream->sendMessage('solutionError', $this->exceptionFormatter->format($exception));
×
110
        } finally {
111
            $eventStream->close('solutionFinished');
×
112
        }
113

114
        return new Core\Http\Response();
×
115
    }
116

117
    private function isRequestSupported(Message\ServerRequestInterface $request): bool
2✔
118
    {
119
        if (!SSE\Stream\SelfEmittingEventStream::canHandle($request)) {
2✔
120
            return false;
1✔
121
        }
122

123
        return Utility\HttpUtility::uriMatchesRequest(self::ROUTE_PATH, $request);
1✔
124
    }
125
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc