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

lmc-eu / matej-client-php / 7527331519

15 Jan 2024 10:11AM UTC coverage: 100.0%. Remained the same
7527331519

Pull #135

github

web-flow
Merge 117257645 into 9666a6254
Pull Request #135: Update to new coding standard

20 of 21 new or added lines in 5 files covered. (95.24%)

400 existing lines in 23 files now uncovered.

758 of 758 relevant lines covered (100.0%)

18.54 hits per line

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

100.0
/src/Http/Plugin/ExceptionPlugin.php
1
<?php declare(strict_types=1);
2

3
namespace Lmc\Matej\Http\Plugin;
4

5
use Fig\Http\Message\StatusCodeInterface;
6
use Http\Client\Common\Plugin;
7
use Http\Promise\Promise;
8
use Lmc\Matej\Exception\AuthorizationException;
9
use Lmc\Matej\Exception\RequestException;
10
use Psr\Http\Message\RequestInterface;
11
use Psr\Http\Message\ResponseInterface;
12

13
/**
14
 * @internal
15
 */
16
final class ExceptionPlugin implements Plugin
17
{
18
    public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise
19
    {
20
        /** @var Promise $promise */
UNCOV
21
        $promise = $next($request);
28✔
22

UNCOV
23
        return $promise->then(function (ResponseInterface $response) use ($request) {
21✔
UNCOV
24
            return $this->transformResponseToException($request, $response);
28✔
UNCOV
25
        });
28✔
26
    }
27

28
    private function transformResponseToException(
29
        RequestInterface $request,
30
        ResponseInterface $response
31
    ): ResponseInterface {
UNCOV
32
        $responseCode = $response->getStatusCode();
28✔
33

UNCOV
34
        if ($responseCode === StatusCodeInterface::STATUS_UNAUTHORIZED) {
28✔
UNCOV
35
            throw AuthorizationException::fromRequestAndResponse($request, $response);
4✔
36
        }
37

UNCOV
38
        if ($responseCode >= 400 && $responseCode < 600) {
24✔
39
            // TODO: use more specific exceptions
UNCOV
40
            throw new RequestException($response->getReasonPhrase(), $request, $response);
16✔
41
        }
42

UNCOV
43
        return $response;
8✔
44
    }
45
}
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