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

eliashaeussler / typo3-solver / 8562357037

04 Apr 2024 10:58PM UTC coverage: 87.107%. Remained the same
8562357037

Pull #221

github

web-flow
[TASK] Update css-loader to v7

| datasource | package    | from   | to    |
| ---------- | ---------- | ------ | ----- |
| npm        | css-loader | 6.11.0 | 7.0.0 |
Pull Request #221: [TASK] Update css-loader to v7

858 of 985 relevant lines covered (87.11%)

6.71 hits per line

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

33.33
/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) 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\Middleware;
25

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

39
use function is_string;
40

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

51
    public function __construct(
4✔
52
        private readonly Configuration\Configuration $configuration,
53
        private readonly Cache\ExceptionsCache $exceptionsCache,
54
        private readonly Formatter\Message\ExceptionStreamFormatter $exceptionFormatter,
55
        private readonly Formatter\WebStreamFormatter $webFormatter,
56
        private readonly Authentication\StreamAuthentication $authentication,
57
    ) {}
4✔
58

59
    public function process(
4✔
60
        Message\ServerRequestInterface $request,
61
        Server\RequestHandlerInterface $handler,
62
    ): Message\ResponseInterface {
63
        // Pass through request if it's not supported
64
        if (!$this->isRequestSupported($request)) {
4✔
65
            return $handler->handle($request);
4✔
66
        }
67

68
        // Create event stream
69
        $eventStream = Http\EventStream::create();
×
70

71
        try {
72
            // Get exception identifier and stream hash
73
            $hash = $request->getQueryParams()['hash'] ?? null;
×
74
            $id = $request->getQueryParams()['exception'] ?? null;
×
75

76
            // Throw exception if stream hash is invalid
77
            if (!is_string($hash)) {
×
78
                throw Exception\AuthenticationFailureException::create();
×
79
            }
80

81
            // Authenticate with stream hash
82
            $this->authentication->authenticate($hash);
×
83

84
            // Throw exception if exception identifier is invalid
85
            if (!is_string($id)) {
×
86
                throw Exception\UnrecoverableExceptionException::forMissingIdentifier();
×
87
            }
88

89
            // Restore exception
90
            $exception = $this->exceptionsCache->get($id);
×
91

92
            // Throw exception if original exception cannot be restored
93
            if ($exception === null) {
×
94
                throw Exception\UnrecoverableExceptionException::create($id);
×
95
            }
96

97
            // Create solver
98
            $solver = new ProblemSolving\Solver($this->configuration, $this->webFormatter);
×
99

100
            // Send solution stream
101
            foreach ($solver->solveStreamed($exception) as $solution) {
×
102
                $eventStream->sendMessage('solutionDelta', $solution);
×
103
            }
104
        } catch (Throwable $e) {
×
105
            $eventStream->sendMessage('solutionError', $this->exceptionFormatter->format($e));
×
106
        } finally {
107
            $eventStream->close('solutionFinished');
×
108
        }
109

110
        return new Core\Http\Response();
×
111
    }
112

113
    private function isRequestSupported(Message\ServerRequestInterface $request): bool
4✔
114
    {
115
        if ($request->getHeader('Accept') !== ['text/event-stream']) {
4✔
116
            return false;
2✔
117
        }
118

119
        return Utility\HttpUtility::uriMatchesRequest(self::ROUTE_PATH, $request);
2✔
120
    }
121
}
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